gpt-4-0314· openai
Suzhen/CodeChat
fivem lua I've got a variable containing numbers eg price = 100000 how could i make it…
- User
fivem lua I've got a variable containing numbers
eg
price = 100000
how could i make it so it looks like 100,000?
- Assistant
You can create a function that formats the number using string manipulation. Here's an example:
function formatNumber(n) local formatted = tostring(n) local k while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if (k == 0) then break end end return formatted end price = 100000 formattedPrice = formatNumber(price) print(formattedPrice) -- Output: 100,000This function uses a loop to insert the commas in the correct positions. You can then call this function with your number to get the formatted string with commas.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.