View Full Version : Rounding a number, How?
mrapelje 02232004, 04:45 AM I need to take a number say 3.625 and round it to it nearest whole number... I.E. 4, Or if someone knows how to truncate a number that would be good too 3.625 > 3. I have not been able to find this in the reference and or searches. I relize that this is a newbie question but then thats me when it comes to MaxScript.
Thanks.


Originally posted by mrapelje
I need to take a number say 3.625 and round it to it nearest whole number... I.E. 4, Or if someone knows how to truncate a number that would be good too 3.625 > 3. I have not been able to find this in the reference and or searches. I relize that this is a newbie question but then thats me when it comes to MaxScript.
Thanks.
"ceil" goes up, "floor" goes down.
Found under "Number Values" topic.
mrapelje
02232004, 05:42 AM
Thank you very much Bobo. I saw that in Number Values and:
I tried (3.375)floor > Error
and not
floor(3.375). > 3
Should have kept trying.
Thanks again.
Originally posted by mrapelje
Thank you very much Bobo. I saw that in Number Values and:
I tried (3.375)floor > Error
and not
floor(3.375). > 3
Should have kept trying.
Thanks again.
The Help says:
floor <number>
Returns the nearest whole number less than or equal to number. The result is always a float.
and not
<number> floor
You don't need the () around btw.
magicm
02232004, 08:29 AM
If you want to round to the nearest integer (floor 3.625 returns 3, not 4), try this function (can also be found in scripts/examples/Function_RoundTo.ms)
 rounds a value to n decimal places
fn round_to val n =
(
local mult = 10.0 ^ n
(floor ((val * mult) + 0.5)) / mult
)
 example
(round_to 3.625 0) as integer
 Martijn
CGTalk Moderation
01172006, 12:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002014, Jelsoft Enterprises Ltd.