Jump to content

Predecimal digits with float


MaddDogg

Recommended Posts

Posted

Hi!

I'm currently working on a car system and I just tried something out at the odometer.

The number is shown digitally using dxDrawText and has 2 decimal digits.

But now I thought, let's have some more digits in front of the decimal position.

But the problem is that when I use a directive inside of string.format with a number in front of the '%', it naturally uses this number for the digit amount of decimal digits. On the other hand, the %d directive uses this system to determine the amount of decimal digits. (I hope you can still follow me :P)

Now I came up with the following, but I just ask myself, if there's a simpler way to do it:

local integer = string.format("%07d", kmDistance) -- getting the integer value for the predecimal digits
local decimals = string.sub(string.format("%.2f", kmDistance - math.floor(kmDistance)), 2, 4) -- this creates the string holding the decimal digits - the '0' in front of it is cut away
 
dxDrawText(integer .. decimals,scrW*0.3,scrH*0.9297,scrW*0.3661,scrH*0.9619,tocolor(50,65,100,255),1.0,"default-bold","center","center",true,false,true) -- drawing the odometer number

So, is there a better way to do this?

And is it a problem do have this in an onClientRender handler function? Or is it a bit too heavy for slow PCs?

Thanks for any help in advance.

Madd

lss_ad_banner.png
Posted
And is it a problem do have this in an onClientRender handler function? Or is it a bit too heavy for slow PCs?

its not a problem

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...