Matevsz Posted June 14, 2016 Posted June 14, 2016 Hi, I created hud money with pennies. After loading shows $00.00 instead of $000000.00 function HudMoney() local money = string.format("%.2f", getPlayerMoney(getLocalPlayer())) dxDrawText("$"..money.."", 1455, 53, 1478, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) end And after entering 25.50, gives us the same 25 whether it is a bad string.format?
KariiiM Posted June 14, 2016 Posted June 14, 2016 function HudMoney() local money = string.format ( "%09d", getPlayerMoney ( getLocalPlayer ( ) ) ) dxDrawText("$"..money.."", 1455, 53, 1478, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) end
Matevsz Posted June 14, 2016 Author Posted June 14, 2016 You see $ 000000000, and how to make $000000.00?
KariiiM Posted June 14, 2016 Posted June 14, 2016 Try that, function HudMoney() local money = string.format ( "%.8f", getPlayerMoney ( getLocalPlayer ( ) ) ) dxDrawText("$"..money.."", 1455, 53, 1478, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) end
-Doc- Posted June 15, 2016 Posted June 15, 2016 function HudMoney() local cash = getPlayerMoney(getLocalPlayer()) money = "$"..convertNumber(cash) dxDrawText("$"..money.."", 1455, 53, 1478, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) end 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 My scripting skills
Matevsz Posted June 15, 2016 Author Posted June 15, 2016 See $$0 And error in db3: attempt to compare string with number
Walid Posted June 15, 2016 Posted June 15, 2016 function HudMoney() local cash = getPlayerMoney(getLocalPlayer()) dxDrawText("$"..formatNumber(cash).."", 1455, 53, 1478, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) end function formatNumber(n) if (not n) then return "Error catching data" end local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$') return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right end Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Matevsz Posted June 15, 2016 Author Posted June 15, 2016 Edit: See $0 and add player money see $54,454,454 and how to do so after the entry could be seen as: I have to enter a zero in dxDrawText?
#RooTs Posted June 15, 2016 Posted June 15, 2016 try 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 function HudMoney() local money = string.format ( "%.8f", getPlayerMoney ( getLocalPlayer ( ) ) ) dxDrawText("$"..convertNumber(money).."", 1455, 53, 1478, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) end
#RooTs Posted June 15, 2016 Posted June 15, 2016 or try 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 function HudMoney() local money2 = getPlayerMoney(getLocalPlayer()) local money = string.format ( "%.8f", getPlayerMoney ( getLocalPlayer ( ) ) ) if money2 < -0 then dxDrawText("$"..money2.."", 1455, 53, 1478, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) else dxDrawText("$"..convertNumber(money).."", 1455, 53, 1478, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) end end
Matevsz Posted June 15, 2016 Author Posted June 15, 2016 I would like to x6 ordinary money and pennies together x2 (.00) = $000000.00 and only a pittance without dividing into $000,000,000
#RooTs Posted June 15, 2016 Posted June 15, 2016 I would like to x6 ordinary money and pennies together x2 (.00) = $000000.00 and only a pittance without dividing into $000,000,000 you tried to adjust the string of numbers of string? local variable = "%011d" -- add number 03 or 02 EX: "%0 03 d" local money1 = string.format(variable, getPlayerMoney(getLocalPlayer()))
Matevsz Posted June 15, 2016 Author Posted June 15, 2016 local money = string.format("%.2f", getPlayerMoney(getLocalPlayer())) dxDrawText("$"..money.."", 1455, 53, 1478, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) See $0.00 Now add the rest of the digits "0"? Gui Editor: dxDrawText("$", 1455, 53, 1478, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) dxDrawText("0", 1474, 53, 1497, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) dxDrawText("0", 1493, 53, 1516, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) dxDrawText("0", 1512, 53, 1535, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) dxDrawText("0", 1531, 53, 1554, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) dxDrawText("0", 1550, 53, 1573, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) dxDrawText("0", 1569, 53, 1592, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) dxDrawText(".", 1588, 53, 1611, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) dxDrawText("0", 1598, 53, 1621, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false) dxDrawText("0", 1617, 53, 1640, 86, tocolor(255, 255, 255, 255), 1.50, "pricedown", "left", "top", false, false, false, false, false)
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