AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Only display nums to right of decimal (https://forums.alliedmods.net/showthread.php?t=60595)

hlstriker 09-07-2007 21:52

Only display nums to right of decimal
 
How can I only display the numbers to the right of the decimal point?

johnjg75 09-08-2007 01:41

Re: Only display nums to right of decimal
 
PHP Code:

stock ExplodeStroutput[][], max_leninput[], delimiter )
{
    new 
nIdx 0nLen = (copycoutput[nIdx], max_leninputdelimiter ))
    while( 
nLen strlen(input) )
        
nLen += (copycoutput[++nIdx], max_leninput[nLen], delimiter ))
    return


-Then just make an output variable like numbers[2][10]
-Make the number to a string and put it in input and set max_len to the length of the number
- Set delimiter to '.'

It should look similar to this:
Code:

ExploadeStr(numbers,9,numbertoseparate,'.')
The string will be separated into two parts, the number before the decimal and the number after the decimal.
numbers[0] contains the numbers before the decimal
numbers[1] contains the numbers after the decimal

Then you can just convert the string back to a number if you need to.

hlstriker 09-08-2007 02:23

Re: Only display nums to right of decimal
 
I thought about using a method like that at first, but then a friend figured this method out for me...

PHP Code:

new Float:totalTime 123.456789
new roundTime floatround(totalTimefloatround_floor);

// If you wanted 3 digits...*1000 and %03d and so on...
new decimals floatround(floatsub(totalTimefloat(roundTime)) * 100floatround_floor);
client_print(0print_chat"Decimal = %02d"decimals);

// That would print 45 



All times are GMT -4. The time now is 16:01.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.