Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

skyline01
New Contributor

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

;

Tags (1)
1 Solution

Accepted Solutions
luismadriz
Valued Contributor

Re: How to display numbers with 2 decimal places

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

9 Replies
OmarBenSalem
Esteemed Contributor

Re: How to display numbers with 2 decimal places

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
New Contributor

Re: How to display numbers with 2 decimal places

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
New Contributor

Re: How to display numbers with 2 decimal places

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
Esteemed Contributor

Re: How to display numbers with 2 decimal places

please try as I showed u:

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


skyline01
New Contributor

Re: How to display numbers with 2 decimal places

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
Esteemed Contributor

Re: How to display numbers with 2 decimal places

U should try to see .

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

good luck !

luismadriz
Valued Contributor

Re: How to display numbers with 2 decimal places

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
Valued Contributor

Re: How to display numbers with 2 decimal places

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
New Contributor

Re: How to display numbers with 2 decimal places

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.

Community Browser