#Just_Me Posted December 12, 2015 Share Posted December 12, 2015 hello guys i have a question which is how can i get the number of the commas or the points ? i mean like this: 1.000.000 the points are 2 or 1,000,000 the commas are 2 how can i get those by using string.find ? Link to comment
1LoL1 Posted December 12, 2015 Share Posted December 12, 2015 You mean this? function convertNumber ( number ) local formatted = number 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: local money = getPlayerMoney(source) guiSetText(label, "Money: "..convertNumber(money).."") result: xx,xxx,xxx Link to comment
#Just_Me Posted December 12, 2015 Author Share Posted December 12, 2015 nah i want the number of the commas or the points in the numbers like this 1.000.000 the number of the points are 2 i want some help to get it by a code not making a points or commas i need to get them Link to comment
Noki Posted December 13, 2015 Share Posted December 13, 2015 http://www.lua.org/pil/20.2.html As we can see, we can't just use string.find(var, ".") because .find is meant to find patterns in strings and not strings within strings. That's why there is "%d", "%w" etc. And, "." matches all characters according to the link above. Since we're looking for a pattern, we need to use the pattern operator before what we want to find (%). So string.find(var, "%.") would work. From this we can also see string.find has an argument on the end of it called plain. That matches a plain character without any pattern operators (so I can search for just "w" instead of "%w" which matches alphanumeric characters. So, you can do string.find(var, ".", 1, true). 1 represents the string index to begin at. tl;dr var = "100.000.000" string.find(var, "%.") -- or string.find(var, ".", 1, true) 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