Matevsz Posted June 14, 2016 Share 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? Link to comment
KariiiM Posted June 14, 2016 Share 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 Link to comment
Matevsz Posted June 14, 2016 Author Share Posted June 14, 2016 You see $ 000000000, and how to make $000000.00? Link to comment
KariiiM Posted June 14, 2016 Share 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 Link to comment
-Doc- Posted June 15, 2016 Share 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 Link to comment
Matevsz Posted June 15, 2016 Author Share Posted June 15, 2016 See $$0 And error in db3: attempt to compare string with number Link to comment
Walid Posted June 15, 2016 Share 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 Link to comment
Matevsz Posted June 15, 2016 Author Share 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? Link to comment
#RooTs Posted June 15, 2016 Share 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 Link to comment
#RooTs Posted June 15, 2016 Share Posted June 15, 2016 See $0.00000000 is not o'que you wanted? Link to comment
#RooTs Posted June 15, 2016 Share 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 Link to comment
Matevsz Posted June 15, 2016 Author Share 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 Link to comment
#RooTs Posted June 15, 2016 Share 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())) Link to comment
Matevsz Posted June 15, 2016 Author Share 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) 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