Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make a IntValue change from a NumberValue?

Asked by 4 years ago

Hey im trying to display a IntValue (with a text label) with a NumberValue How do i do that. I dont want it to display decimals but i need decimals to add some features.

0
math.floor(value) to round down. Or math.ceil(value) to round up the8bitdude11 358 — 4y
0
wdym value the8bitdude11 woahsnake 4 — 4y
0
(value), as in the value you want to round Koap2 17 — 4y
0
If you only want integers just use a IntValue and just add integers. BlackOrange3343 2676 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

As the comments say, use math.floor().

math.floor(num) returns num in its truncated form (to truncate a number means to chop off the decimal point, which means that 3.95 would become 3). math.ceil(num) (which is what you shouldn't use) returns the 'raised' form of num to the next integer. (You should not use this because math.floor() can do this. I'm about to show you how.)

If you want to round a number, then use math.floor(num + 0.5). Do not use math.ceil().

Demonstration:

print(math.floor(3.2 + 0.5)) -- Prints 3 because 3.2 + 0.5 = 3.7

print(math.floor(3.6 + 0.5)) -- Prints 4 because 3.6 + 0.5 = 4.1
Ad

Answer this question