Hello FiveM Community, I got a decent Issue on my Server. So I found out that my Server has some problem when it comes to “numbers” I found my issue out, because I used a Script where you need to enter Values like “0.04, 0.03, 1.02” and …, sooo, normally it would use the number I type in like “0.04” but instead it makes a “0.04000009” or something, that is very annoying and I have no Idea where it comes from, I also tried another Hoster/Server, no luck. Not everyone has this issue, I see for some people it works normal and on my local host its fine too, I add an Image that shows my issue. (In the Image I printed the args for “0.04”. Thanks in Advance for helping and have a good one!

I think this might be related to your issues

But I would simply just round the decimal places you need.
This utility function may help you to achieve this.

function round(num, numDecimalPlaces)
	local mult = 10^(numDecimalPlaces or 0)
	return math.floor(num * mult + 0.5) / mult
end
1 Like

Thank you for your reply, thanks for the tip, sadly I still being stuck here, I tried some things, but I don’t get it to work, do you maybe have an idea how I could make the function complete functional? Im kinda stuck at this part.

Im not sure how your system is working but It should work like this

Input: 0.04

function round(num, numDecimalPlaces)
	local mult = 10^(numDecimalPlaces or 0)
	return math.floor(num * mult + 0.5) / mult
end


local input = yourvalue
local roundedvalue = round(input, 2) -- The function round returns your the Value (First Value is your number, second is how much Decimal places you want.
print(roundedvalue)

Thank you, so I have to paste it into a function.lua right?

if you send me your chat script i can implement it for you

Much appreciated, here is my Chat resource.
chat.zip (216.2 KB)

can you tell me where your print is?

The print is in another random resource just to test it, here is the code for the print: RegisterCommand("test", function(source, args, rawCommand) print(tonumber(args[1])) end, false)

This is how it works with your test command

function round(num, numDecimalPlaces)
    local mult = 10^(numDecimalPlaces or 0)
    return math.floor(num * mult + 0.5) / mult
end

RegisterCommand("test", function(source, args, rawCommand) 
    local input = tonumber(args[1])
    local rounded = round(input, 3)
    print(rounded)
end, false)

Thank you very much, can I ask, is that now for all these Decimal Numbers? Because I was using a BAC Script where I can set a BAC Level, and there I had the issue that it was not “0.04” or something instead it was “0.040006” like in the picture, do I have to implement it in every script or will this code fix it for the whole server?

Nvm got it! Alright my Issue was solved here, Thanks for you both guys for helping me!

1 Like