## Round a number

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

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

### Round a number

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

Grovkillen
Automation Wizard
Posts: 463
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

### Re: Round a number

Simply truncate it.
Let>ME=%Script%

Running: 15.0.9

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

### Re: Round a number

but how?

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

### Re: Round a number

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

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

### Re: Round a number

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

Divide by 10, trunc and x10 again.

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

### Re: Round a number

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

``````