Round a number

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
conjure
Pro Scripter
Posts: 63
Joined: Thu Jan 12, 2012 3:05 pm

Round a number

Post by conjure » Sat Nov 02, 2019 8:32 am

Is it possible to round a number like this in the example?
for example
Round(12.25) = 12
Round(12.50) = 12
Round(12.75) = 12

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Round a number

Post by Grovkillen » Sat Nov 02, 2019 9:55 am

Simply truncate it.
Let>ME=%Script%

Running: 15.0.24
version history

conjure
Pro Scripter
Posts: 63
Joined: Thu Jan 12, 2012 3:05 pm

Re: Round a number

Post by conjure » Sat Nov 02, 2019 10:38 am

but how?

conjure
Pro Scripter
Posts: 63
Joined: Thu Jan 12, 2012 3:05 pm

Re: Round a number

Post by conjure » Sat Nov 02, 2019 10:42 am

i found it
Let>a=301.6
Let>a={Trunc(%a%)}
msg a

conjure
Pro Scripter
Posts: 63
Joined: Thu Jan 12, 2012 3:05 pm

Re: Round a number

Post by conjure » Sat Nov 02, 2019 11:00 am

Grovkillen wrote:
Sat Nov 02, 2019 9:55 am
Simply truncate it.
Is it possible to truncate a number like this?
Round(12) = 10
Round(15) = 10
Round(19) = 10

flamerz
Newbie
Posts: 3
Joined: Fri Oct 04, 2019 9:01 pm

Re: Round a number

Post by flamerz » Sat Nov 02, 2019 8:10 pm

Divide by 10, trunc and x10 again.

conjure
Pro Scripter
Posts: 63
Joined: Thu Jan 12, 2012 3:05 pm

Re: Round a number

Post by conjure » Sat Nov 02, 2019 10:41 pm

found it again

Code: Select all


label>start

random>9999,a
if>a>1000
let>rounding=1000
goto>found
endif
if>a>100
let>rounding=100
goto>found
endif
if>a>10
let>rounding=10
goto>found
endif


label>found
let>b=a
Let>b={Trunc(%b%/%rounding%)*%rounding%}
msg %a% %b%
wait>1
goto>start



Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts