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

Username:   Password: 
 RegisterRegister   
 Restricting variables to 2 decimal places
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Da_Big_Ticket




PostPosted: Mon Oct 31, 2005 2:32 pm   Post subject: Restricting variables to 2 decimal places

i know that if you want to restrict the number of decimal spaces on an output it would be :

variable : 0 : 2

However, I am font drawing variables in my program, and these variables have values assigned to them

For example balanceowing := opening + interest
Font.Draw realstr (balanceowing,5,), 120 , 230, font1, white)

How would you restrict this output to 2 decimals? Sinse it does have a values assigned to it via other variables and it is font drawn


Also if anyone knows how to get rid of the 7.14321e6 exponent junk would you be able to give me the solution? Thanks
Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Mon Oct 31, 2005 2:40 pm   Post subject: (No subject)

I havent tested this this might work
var v2 := realstr(variable, 2)
v2 := v2(1..index(v2,".")+2)
[Gandalf]




PostPosted: Mon Oct 31, 2005 4:53 pm   Post subject: (No subject)

I am fairly sure you simply mean to round a value to 2 decimal places instead of just cutting it off?

code:
var pi : real := 3.14159
put pi
put round(pi * 100) / 100
MysticVegeta




PostPosted: Mon Oct 31, 2005 6:52 pm   Post subject: (No subject)

code:
var pi : real := 3.14159
put frealstr (pi, 2, 2)

even more wyas of doing that!@
Da_Big_Ticket




PostPosted: Thu Nov 03, 2005 8:54 am   Post subject: (No subject)

Thanks guys. I got it to work. What a relief
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  [ 5 Posts ]
Jump to:   


Style:  
Search: