Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,203 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 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 | chip programmers | 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