Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How round DOWN a number?

I have a small problem. I want to make a currency converter, but can't figure out how to tackle this problem. Example below:

WhatIHave = 55

WhatIGet = WhatIHave/10
--Output: 5.5

How do I round down WhatIGet to the lowest whole number (in this case, 5). I don't want to round it up.

3 answers

✓ Accepted answer

You use math.floor

a = 5.5
print(math.floor(a))

And coltn5000, that is just long, you get the same result with

function round(n)
	return math.floor(n+.5)
end

print(round(5.6), round(5.4))

5 6

15 comments

1

I downrated it? Nope, someone else. I can't downrate... I need atleast 5 reputation to downrate. I have -9...

1

Just to let you know he said he wanted to make a converter I made an example so to say I also made a round function that way depending on where the decimal is he probably asked to lower it because he didn't know how to round it

1

I know how to round in real, but not on ROBLOX,

1

Just to let you know he said he wanted to make a converter I made an example so to say I also made a round function that way depending on where the decimal is he probably asked to lower it because he didn't know how to round it

1

Also, wouldn't the output say 6 5 instead of 5 6? because umm, 5.6+0.5 = 6.1 so round(6.1) = 6???

1

Just to let you know he said he wanted to make a converter I made an example so to say I also made a round function that way depending on where the decimal is he probably asked to lower it because he didn't know how to round it

1

No math.ceil takes it up it doesn't add the decimal also I meant roblox not real life

1

No math.ceil takes it up it doesn't add the decimal also I meant roblox not real life

1

Mind deleting the duplicates? You're posting duplicate comments apparently...

1

@lomb How do I replace n with WhatIHave?? It's a little confusing...

1

n is the parameter. You call the function like round(WhatIHave). But if you want to only round down use math.floor(WhatIHave)

1

So would this work?: while true do wait() math.floor(WhatIHave) end I did an infinite loop because if you type once, hit enter then try again, it won't round...

1

It would work, but you are not doing anything with the rounded down value

1

Mine is downvoted. Why? it's a simple and objective answer.

1

@lomb, What's your ROBLOX username, I have to credit you. @Tes, Idk, I can't downvote even though it's my question...

 WhatIHave = 55

WhatIGet = math.floor(WhatIHave/10)
--Output: 5

math.floor will round it down. (more info)

2 comments

0

Why the -1?

0

math.floor() will round down by itself. why divide by 10? how does 55 round down to 5?

Do this

function Round(value)
 if (value%1 > .5) then
   return math.ceil(value) -- rounds the value up
 else
  return math.floor(value) -- rounds the value down
 end
end


function Convert(Amount, ReachAmount) -- the amount, and max amount
  if (Amount >= ReachAmount) then
   Amount = Amount - ReachAmount -- this will be the amount the person gets if reached to the reach amount
  return Round(Amount)
  end
end

local newAmount = Convert(WhatIHave, 10)
print(newAmount) -- print transaction to the output

1 comment

0

This will convert and round the amount. Please up vote my answer

This discussion is preserved as it was. New answers, comments, and votes are closed.