
-----------------------------------
MattyGG
Tue Feb 07, 2006 2:50 pm

Help with displaying real values
-----------------------------------
I'm trying to display real values as dollar values, but if the user inputs a real value to under 2 decimal places, it will only output up to those two spaces...eg, the user inputs "6.5" it outputs "6.5" when i want it to output "6.50"

-----------------------------------
Tony
Tue Feb 07, 2006 3:04 pm


-----------------------------------

put real_value:2

where :n will format to n decimal places.

-----------------------------------
Delos
Tue Feb 07, 2006 4:33 pm


-----------------------------------

put real_value:2

where :n will format to n decimal places.

Oh, so close Tony, so very close.  The first colon : number complex refers to the number of spaces allocated to that output.  For decimal places, you'll want the second colon : number.

i.e.


put real_value : 0 : 2
% 0 means it may use as much space as necessary.


-----------------------------------
Cervantes
Tue Feb 07, 2006 4:43 pm


-----------------------------------
This can also be done using frealstr which is a type convertion from real to string, where f stands for fraction.

frealstr (r : real, width, fractionWidth : int)


put frealstr (6.5, 0, 2)


It's basically the same as what Delos has, there.  The only difference is that this is a manual type convertion, and thus allows you to use it in Font.Draw or other such places where you need a string.
