Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
skyline01
Creator
Creator

How to display numbers with 2 decimal places

I am working in Qlik Sense Desktop (June 2017).  I have an app in which I am rounding certain fields to 2 decimal places.  After the rounding (via Round(field, 0.01)), I have noticed that some numbers don't retain 2 decimal places.  For example, if the rounded number is something like '3.00', the number gets displayed as '3'.  If the rounded number is something like '3.10', the number gets displayed as '3.1'.  How can I keep the trailing zeros, to always have 2 decimal places displayed after the number?

My script is like:

Load

    Round(Field1, 0.01) as Field1

Resident

    T1

;

The following does not resolve my problem:

Load

    Num(Round(Field1, 0.01), #.00) as Field1

Resident

    T1

;

1 Solution

Accepted Solutions
luismadriz
Specialist
Specialist

For example using 3 decimals:

T1:

Load * Inline

[Field1

2353.1010101

3.33812

3.9999

3.0022

3.0

2];

NewTable:

Load *,

     Round(Field1,0.001) as Field2

Resident T1;

Drop Table T1;

Untitled.png

View solution in original post

9 Replies
OmarBenSalem

why you're trying this in the script? u can always (EASILY)  control this in the front end.

maybe:

Num(round(Field1,0.01), '# ##0,00 ')


nbr:

load *, Num(round(nbr,0.01), '# ##0,00 ')

Inline [

nbr

2353.10

3.333

3.22

3.000

];

result

Capture.PNG

skyline01
Creator
Creator
Author

I'm in a strange situation where it has to be done in the script.  I tried your solution (wrap the number format with tick marks).  It didn't work.

skyline01
Creator
Creator
Author

Here is a more detailed version of my script:

T2:

   NoConcatenate Load

   [ID]

   ,Num(Round(Field1, 0.01), '#.00') as Field1Rounded

Resident

   T1

Order By

   ID desc

;

OmarBenSalem

please try as I showed u:

Num(round(Field1,0.01), '# ##0,00 ')


skyline01
Creator
Creator
Author

I did (with the minor tweak of '#,##0.00 ', as I am American.)  Your solution works on the data from the inline load.  However, it doesn't work on my actual data.  That is why I posted a more detailed version of my script.  I'm wondering if it has something to do with the fact that my data comes from a resident load.  Perhaps the rounding and formatting need to first be applied to the data source (i.e., to table T1).

OmarBenSalem

U should try to see .

Sorry mate , i have to go now it's being late for me.. 00:15 pm..

good luck !

luismadriz
Specialist
Specialist

Hi Case,

This is enough for what you need

Round(Field1, 0.01) as Field2

The problem you seem experience is because you're using the same field name. Create a new field and then if you want, drop the old field. Keep both if you want to see the difference

I hope this helps,

Cheers,

Luis

luismadriz
Specialist
Specialist

For example using 3 decimals:

T1:

Load * Inline

[Field1

2353.1010101

3.33812

3.9999

3.0022

3.0

2];

NewTable:

Load *,

     Round(Field1,0.001) as Field2

Resident T1;

Drop Table T1;

Untitled.png

skyline01
Creator
Creator
Author

Thank you.  This is what I needed.  I wasn't aware that I had to re-name the fields to a different name, drop the original fields (via Drop Fields), and then switch the field names back to the original names.