MaddDogg Posted April 9, 2010 Share Posted April 9, 2010 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 ) 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 Link to comment
dzek (varez) Posted April 9, 2010 Share Posted April 9, 2010 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 Link to comment
DiSaMe Posted April 10, 2010 Share Posted April 10, 2010 You can round decimals in this way: rounded_value = math.floor(unrounded_value*100)/100 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now