
-----------------------------------
Zeppelin
Sat Jan 19, 2008 12:41 pm

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

-----------------------------------
Nick
Sat Jan 19, 2008 12:47 pm

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
Sat Jan 19, 2008 12:49 pm

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
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
Sat Jan 26, 2008 7:12 pm

Re: Rounding to two decimal places
-----------------------------------
use round funct

-----------------------------------
Ultrahex
Sun Jan 27, 2008 2:35 pm

Re: Rounding to two decimal places
-----------------------------------
put 1.24214124214:0:2 rounds to 2 decimal places :) also (since it already was bumped from last week)

-----------------------------------
Mackie
Sun Jan 27, 2008 2:56 pm

RE:Rounding to two decimal places
-----------------------------------
But that won't work if he's using Draw.Text.

-----------------------------------
ericfourfour
Sun Jan 27, 2008 3:47 pm

Re: Rounding to two decimal places
-----------------------------------
Here's the function I use:
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.
