#DaMiAnO Posted December 1, 2011 Posted December 1, 2011 Hello! I want "cut" the number in "tonumber". I have this code: tonumber(kmh) , but KM/h is displays, for example: 3.444444545488784848. I want only 3.44 KM/h. It's possible to do that? Sorry for my English.
Castillo Posted December 1, 2011 Posted December 1, 2011 You can use math.floor, but that will make it: 3 KM/h. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
#DaMiAnO Posted December 1, 2011 Author Posted December 1, 2011 What to use "math.floor"? Wiki doesn't have infs for math.floor. Sorry for my English.
myonlake Posted December 1, 2011 Posted December 1, 2011 Wiki doesn't have everything, that's why you should check lua.org If I helped you, please click the like button on the right Thanks!
Castillo Posted December 1, 2011 Posted December 1, 2011 kmh = math.floor(tonumber(kmh)) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
50p Posted December 1, 2011 Posted December 1, 2011 Hello!I want "cut" the number in "tonumber". I have this code: tonumber(kmh) , but KM/h is displays, for example: 3.444444545488784848. I want only 3.44 KM/h. It's possible to do that? kmh = tonumber( string.format( "%.2f", 3.444444545488784848 ) ); -- kmh == 3.44 - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
Bssol Posted December 1, 2011 Posted December 1, 2011 If you want to make it to the nearest integer number, you can use solidsnake's code. But if you want to make it with a few decimal numbers, you need to put this function to your script. function math.round(number, decimals, method) decimals = decimals or 0 local factor = 10 ^ decimals if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor else return tonumber(("%."..decimals.."f"):format(number)) end end so, If you have a number of such 3.26897 math.round(3.26897, 2) --- 3.26 math.round(3.26897, 3) --- 3.268
#DaMiAnO Posted December 2, 2011 Author Posted December 2, 2011 Thanks for help! Sorry for my English.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now