How do I convert this string into a number?

Hello, ive been having some trouble with this number

image

The top one is me using tonumber() and the bottom is the string. I think maybe the number is to small for to number. How else can I make this a number?

1 Like

local number = 0.0002269
print(number)
I’m almost sure this isn’t what you looking for, however, if you can enlighten me more about the situation, that will be better.

I am not very sure about this, but what about concatenating the string like so:

a = 0
b = 0000029

local numberToString = a.."."..b

I think he means he wants to turn the string into a number

oh ok, what about

local numberString = "0.00002269"
numberString = string.split(numberString, ".")
local integer = numberString[1] -- integer basically mean whole number
local decimal = numberString[2]

if you just want to use the number for calculations the scientific notation doesn’t matter if you want to to print the number use string.format()
The % just means to get a value after the , of the string
The .8 means that there will be 8 numbers after the decimal point, if there are no values it will just fill it with zeros
The f represents a foating point number(float).
Altough method will be inacurate after the first 17 digits this shouldn’t realy matter

number = 0.0000223
print(string.format("%.8f", number))

Output:
0.00002230

4 Likes

did you forget string.format :joy:

2 Likes

Haha, probably. This isn’t printf.

1 Like

F, didn’t notice. fixed it though