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

Username:   Password: 
 RegisterRegister   
 Rounding to two decimal places
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Zeppelin




PostPosted: Sat Jan 19, 2008 12:41 pm   Post subject: Rounding to two decimal places

Ok I started working on a game last week. Basicly it's going to be a turn based strategy game. One of the things I'm trying to do is give the player complete control of their army as in develop whatever weapons they can imagine weather it's a giant gravity bomb or a light weight assault rifle etc. Now what I want to know is if it's possible to round real numbers of when I display them using Draw.Text.

What I want to do is round off some numbers to two decimal places (eg. Money). Is it possible to do this using when using Draw.Text?

Thanks
Sponsor
Sponsor
Sponsor
sponsor
Nick




PostPosted: Sat Jan 19, 2008 12:47 pm   Post subject: RE:Rounding to two decimal places

multiply the number by 100, round, then divide by 100

example
4.265
426.5
427
4.27
HeavenAgain




PostPosted: Sat Jan 19, 2008 12:49 pm   Post subject: RE:Rounding to two decimal places

yep, you could, and you don't even have to write your own rounding method, what i found in the F10 help was this
code:
put frealstr(1.125,0,2)

1.125 is a real, you can use your money variable or whatever variable to replace it, and 0 is the width, for formmating the adjustment, and 2 is the rounding precision
mo




PostPosted: Sat Jan 26, 2008 7:12 pm   Post subject: Re: Rounding to two decimal places

use round funct
Ultrahex




PostPosted: Sun Jan 27, 2008 2:35 pm   Post subject: Re: Rounding to two decimal places

put 1.24214124214:0:2 rounds to 2 decimal places Smile also (since it already was bumped from last week)
Mackie




PostPosted: Sun Jan 27, 2008 2:56 pm   Post subject: RE:Rounding to two decimal places

But that won't work if he's using Draw.Text.
ericfourfour




PostPosted: Sun Jan 27, 2008 3:47 pm   Post subject: Re: Rounding to two decimal places

Here's the function I use:
Turing:
fcn roundn (value : real, nPlaces : int) : real
    var multiply : real := 10 ** nPlaces
    result round (value * multiply) / multiply
end roundn


For a normal round, you round to 0 decimal places. You can round negative or positive decimal places.
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  [ 7 Posts ]
Jump to:   


Style:  
Search: