Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone help me to convert numbers? I need to convert a dot number to a comma number.

Asked by
Nickzus 24
7 years ago

Can someone help me? I need to convert a number for a maping that gives me a number in that format 0.2 then I need to convert it to a format like that 0,2. Thankful Nickzus.

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
local num = 0.2

local com = tostring(num)
for i = 1,#com do
com = com:gsub(".",",")
end

First up you have to convert your number to a string, then You put a loop to the amount of the converted number. This is so that it switches any "." to "," with the gsub (will explain in a second)

Gsub switches a to b in a string and returns the finished value example:

String = "Hey world!"
print(String:gsub("Hey","Hello"))

Output: Hello world!

That should work if I understand what you mean.. You can't convert it into a number as 0,2 since that's not a valid number. If this is not what you mean please leave a comment and tell me.

0
Do not just post joke; explain the reasoning behind your answer. Simply posting code does not help the OP, or asker, to understand the reasoning behind your answer. Why should he do this? Why should he do that? Why did you use a for loop? Why GSub? Your answer is vague. TheeDeathCaster 2368 — 7y
0
1. If he doesn't post anything helping me at all I can't help him. 2. I didn't post an explanation because I don't know what he wants exactly. 3. So first you call my post a joke, then you're saying it's a real post. I'll add an explanation but still. fireboltofdeathalt 118 — 7y
0
Heh, that for loop isn't required at all. As its name suggests, 'gsub' is a GLOBAL substitution. Link150 1355 — 7y
Ad

Answer this question