Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with displaying real values
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MattyGG




PostPosted: 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"
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Feb 07, 2006 3:04 pm   Post subject: (No subject)

code:

put real_value:2

where :n will format to n decimal places.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Delos




PostPosted: Tue Feb 07, 2006 4:33 pm   Post subject: (No subject)

Tony wrote:
code:

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.

code:

put real_value : 0 : 2
% 0 means it may use as much space as necessary.
Cervantes




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: