PDA

View Full Version : Separating thousands with comma



paravantis
29-08-2024, 18:21
Is there an easier way to separate thousands with comma?


Uses "Console"
PrintL format$(123456789.123,"###,###,###.###")
WaitKey

In the code above, we would have to know beforehand how large the value to be printed is, and the code would fail to place all the commas if the value were larger.

We could use


PrintL format$(123456789.123,"###,###,###,###,###,###,###,###.###")

to anticipate larger values, but I wonder if there is a more elegant solution.

paravantis
29-08-2024, 18:36
I am answering my own question.

The code below does the job:


Uses "Console"
PrintL format$(123456789123456.123,"#,###.###")
WaitKey

Petr Schreiber
01-09-2024, 17:52
Thank you for sharing the solution with others!

I suspect even this could work:


uses "console"

printl format$(1212313212313.123456, "#,.000")

waitkey


We should expand the docs to reduce the guesswork.


Petr