Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (Dico), 16,767 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
numbers #160355
10/11/07 04:35
10/11/07 04:35
Joined: Sep 2007
Posts: 49
O
onslaught147 Offline OP
Newbie
onslaught147  Offline OP
Newbie
O

Joined: Sep 2007
Posts: 49
this is a easy question but i cant find the answer to it but, how do you round numbers to a certain decimal point?


The only thing in life you can depend on is death and taxes.
Re: numbers [Re: onslaught147] #160356
10/11/07 13:17
10/11/07 13:17
Joined: Jul 2006
Posts: 150
Deutschland/Germany, nahe Hamb...
dennis Offline
Member
dennis  Offline
Member

Joined: Jul 2006
Posts: 150
Deutschland/Germany, nahe Hamb...
First you could name your thread a bit more "on-topic" (e.g. "How to round numbers?")

-------------------------------------------------------------------

You can build a function yourself using "int" (wdl) or "integer" (lite-c)

Hummel posted this:

Quote:

function round(x) { return(integer(x+0.5)); } ^^so muss das aussehen.

nein-halt!
->so hier: function round(x) { return(integer(x+0.5*x/abs(x))); }
...denn sonst funzts nicht mit negativen Zahlen^^




I think you can change it a bit so that you can select the decimal point..

Try this:

function round(var x, var decimal)
{
x *= 10*decimal;
x = integer(x+0.5*x/abs(x));
x /= 10*decimal;
return(x);
}
(wdl)

function round(x,decimal)
{
x *= 10*decimal;
x = int(x+0.5*x/abs(x));
x /= 10*decimal;
return(x);
}
(lite-c)

Of course aou can shorten this script.
Be careful with large numbers.

(--> I did not try the script)

Re: numbers [Re: dennis] #217630
07/24/08 06:15
07/24/08 06:15
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
Originally Posted By: dennis
First you could name your thread a bit more "on-topic" (e.g. "How to round numbers?")

-------------------------------------------------------------------

You can build a function yourself using "int" (wdl) or "integer" (lite-c)

Hummel posted this:

Quote:
function round(x) { return(integer(x+0.5)); } ^^so muss das aussehen.

nein-halt!
->so hier: function round(x) { return(integer(x+0.5*x/abs(x))); }
...denn sonst funzts nicht mit negativen Zahlen^^


I think you can change it a bit so that you can select the decimal point..

Try this:

function round(var x, var decimal)
{
x *= 10*decimal;
x = integer(x+0.5*x/abs(x));
x /= 10*decimal;
return(x);
}
(wdl)

function round(x,decimal)
{
x *= 10*decimal;
x = int(x+0.5*x/abs(x));
x /= 10*decimal;
return(x);
}
(lite-c)

Of course aou can shorten this script.
Be careful with large numbers.

(--> I did not try the script)




a check for zero should be added to it..

becomes:

function round(x,decimal)
{
if(x==0)
return(0.0);
else
{
x *= 10*decimal;
x = int(x+0.5*x/abs(x));
x /= 10*decimal;
return(x);
}
}
(lite-c)


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1