Computer Science Canada

Rounding to two decimal places

Author:  Zeppelin [ 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

Author:  Nick [ 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

Author:  HeavenAgain [ 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

Author:  mo [ Sat Jan 26, 2008 7:12 pm ]
Post subject:  Re: Rounding to two decimal places

use round funct

Author:  Ultrahex [ 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)

Author:  Mackie [ 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.

Author:  ericfourfour [ 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.


: