botshara Posted December 24, 2015 Share Posted December 24, 2015 Hello guys, which will be the easiest way to format number to decimal. I want allow formats like these > 1 > 1.1 > 1.22 Link to comment
draobrehtom Posted December 24, 2015 Share Posted December 24, 2015 Could you give some more examples, I dont understand what you want? Maybe this can help you: http://www.lua.org/manual/5.1/manual.html 2.5.1 – Arithmetic OperatorsLua supports the usual arithmetic operators: the binary + (addition), - (subtraction), * (multiplication), / (division), % (modulo), and ^ (exponentiation); and unary - (negation). If the operands are numbers, or strings that can be converted to numbers (see §2.2.1), then all operations have the usual meaning. Exponentiation works for any exponent. For instance, x^(-0.5) computes the inverse of the square root of x. Modulo is defined as a % b == a - math.floor(a/b)*b That is, it is the remainder of a division that rounds the quotient towards minus infinity. Link to comment
botshara Posted December 24, 2015 Author Share Posted December 24, 2015 I want allow only 2 numbers after comma if is more than 2 numbers then show error or format to number with 2 numbers after comma Link to comment
Noki Posted December 24, 2015 Share Posted December 24, 2015 math.round(5.924613, 2) > 5.92 The second argument is the number of decimal places. Link to comment
botshara Posted December 25, 2015 Author Share Posted December 25, 2015 math.round(5.924613, 2) > 5.92 The second argument is the number of decimal places. This function doesnt works Link to comment
AMARANT Posted December 25, 2015 Share Posted December 25, 2015 Because it's not a build-in function. You must add it by yourself. See here - https://wiki.multitheftauto.com/wiki/Math.round. Link to comment
Dazee Posted December 26, 2015 Share Posted December 26, 2015 This migth be useful I use it for all of my number formatting, function comma_value(amount) local formatted = amount while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if (k==0) then break end end return formatted end Example of usage: outputChatBox("You have recieved: $" ..comma_value(amount).. " into your bank account",source,0,255,255) Link to comment
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