How to round up to nearest whole number

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
louisharrodine
Posts: 7
Joined: Tue Oct 30, 2012 11:39 am

How to round up to nearest whole number

Post by louisharrodine » Tue Nov 20, 2012 11:47 am

Hi there,

I'm dealing with various decimal numbers:

4.6736583758
28.01392764

etc


How would I round numbers such as these up to the nearest whole number? thanks

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to round up to nearest whole number

Post by Klaus » Tue Nov 20, 2012 12:07 pm

Hi Louis,

you'll be surprised (NOT):
put round(4.6736583758) -> 5
put round(28.01392764) -> 28
:D

Check the dictionary for more options of "round"...


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: How to round up to nearest whole number

Post by dunbarx » Tue Nov 20, 2012 3:14 pm

Hi.

One way to always round to the next highest integer is to;

Code: Select all

on mouseup
   answer roundUp(msg)
end mouseup

function roundUp var
   return round(var + 0.5)
end roundUp
Craig Newman

Post Reply