Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to format Numbers with some decimals?

In one attribute I have a set of numbers that include the following:

10345

0.001

487.723

10.02

16345.1

My customers would like to see these numbers with commas and with no trailing zeros.

10345    ->  10,345

0.001     ->   0.001

487.723   ->  487.723

10.02       ->  10.02

16345.1    -> 16,345.1


When I apply a format of ###,###.###, I get trailing zeros on every number, which is not desired.


Is there a format option that will show both commas and only the significant trailing digits?

Do I have to use an IF stmt to detect the four cases (no decimals, 1 decimal, 2 decimal or 3 decimal) and format appropriately?


John



8 Replies
Gysbert_Wassenaar

Try this format string: num(MyNumber, '###,###')


talk is cheap, supply exceeds demand
buzzy996
Master II
Master II

may be tis,

for.PNG

Not applicable
Author

Gysbert,

That format would not show the decimal portion of the value.

John

Not applicable
Author

Shiva,

The default option does not insert commas.

John

swuehl
MVP
MVP

You probably need a conditional formatting, maybe like

LOAD Value,

  num((Value),'#,##0' & pick(1+ len(subfield(text(Value),'.',2)), '','.0','.00','.000'),'.',',') as Value2

INLINE [

Value

10345

0.001

487.723

10.02

16345.1

];

The format codes description in the HELP talked about that something like this should/could work (except for pure integers):

'#,##0.0##','.',','

but it doesn't work at my side.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I remember discussing something like this a few years ago. Attached is the solution I used at the time.

-Rob

http://masterssummit.com

http://robwunderlich.com

anlonghi2
Creator II
Creator II

Hi John,

try setting the property "Number Format Setting" to Number

Regards

Andrea

MarcoWedel

Hi,

maybe you could concatenate the formated integer part with the unformatted decimal part:

QlikCommunity_Thread_163148_Pic1.JPG

LOAD *,

    Subfield(Num(numbers,'#,###.###'),'.',1)&If(Index(numbers,'.'),'.'&Subfield(numbers,'.',2)) as numbersFormatted

Inline [

numbers

10345

0.001

487.723

10.02

16345.1

];

hope this helps

regards

Marco