lcd.print format with commas AND decimal point

i'd like to have the lcd show commas and a decimal where needed.. like:


there will always be a decimal and 2 numbers after it..

so if i did this:
lcd.print("Output: ")
lcd.print(usage) // but i want it to put out that format as mentioned so it looks like this for example:

Output: 23,000.01
Output: 2.00
Output: .10

First question is why you would ever want to suppress the leading 0 when the value is less than 1?

Adding the commas is a rather manual process. You need to divide the value by 1000 to get the part before the comma (24845 / 1000 = 24), then use the % operator to get the part after the comma (24845 % 1000 = 845), then print the first value, then print the comma, then print the 2nd value.

That works for ints, so you need to convert the float to an int. Then, subtract the int from the float (24845.387 - 24845 = 0.387). Then, multiply by 100.0 and add 0.5 to round the value off, and store as another int (0.387 * 100 = 38.7; 38.7 + 0.5 = 39.2; 39.2 as an int is 39). Then, if the int is less than 10 print a 0 and the int. Otherwise, print the int.

Printing 24, comma, 845, point, 39 will show you 24,845.39 which is 24845.387 to two decimal places.

because it's a money thing.. so the format MUST have the commas in the right places and a decimal with only 2 digits after it.. again the program starts with .00 and then increases accordingly..

these are only examples of the out put required...
.00 // is the default setup start OR 0.00 would be fine too
1,100,000.00 // it will never get this high..

but to show that the commas MUST be in the correct place and that there is a decimal with only 2 digits after it.. not 3 or more after the decimal... it's not a percentage kind of thing so there is absolutely no need for more than 2 digits after the decimal.

.01 will add up to 1.00 accordingly... then continue adding.. like: 1.01 + .05 = 1.06 or 1.00 + .01 = 1.01

Are you storing your values as cents?
You should be.

i want to yes..


hence why i need the format when it adding

like: cash + .01 or cash + .25