Help with displaying real values
Author |
Message |
MattyGG
|
Posted: Tue Feb 07, 2006 2:50 pm Post subject: 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" |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Tue Feb 07, 2006 4:33 pm Post subject: (No subject) |
|
|
Tony wrote:
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.
code: |
put real_value : 0 : 2
% 0 means it may use as much space as necessary.
|
|
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Tue Feb 07, 2006 4:43 pm Post subject: (No subject) |
|
|
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)
code: |
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. |
|
|
|
|
![](images/spacer.gif) |
|
|