int to float, how can that be done correctly ?
#1

Wel lets take an example:

new miliseconds = 5005; // 500.5 seconds
new floateconds = miliseconds / 10; // should return 500,5

But instead of returning 500.5 / 500,5 it returns 0.00000

How can this be done correctly ?

PKR
Reply
#2

From what i can see it should work.
Reply
#3

First, 5005 milliseconds = 5.005 seconds.

Then, it's

new Floateconds = milliseconds / 1000.0
Reply
#4

I think what he put at the top was just an example.
Reply
#5

new tmp[128];
new float:temp = timechallange / 10;
format(tmp, sizeof tmp, "The timechallange record is %f Seconds, type /time to start a time challange!\n", temp);
print (tmp);
gTextDraw = TextDrawCreate(0.0, 380.0, tmp);
TextDrawUseBox(gTextDraw, 1);

returns:
The timechallange record is 0.000000 Seconds, type /time to start a time challange!

(if i put timechallange in the format instead of temp it just gives 2000.., so the var/int timechallange is reachable..)
Reply
#6

I pointed out your mistakes in my post, that you apparently totally ignored.
Reply
#7

Thnx / 10.0 xD

now, is there any way to remove the extra zero's?

now i have 200.000000. 200.0 should be fine
Reply
#8

No you cant remove the extra zero's, floats are always saved with 8 integers behind the comma
But you can denotes how much are shown within the format

%X.Yf

X = denotes how much integer should be before the comma
Y = denotes how much integer should be after the comma

Example

What you want: "%.1f Seconds"

Other Example: "%4.4f Seconds"
Reply
#9

excellent, thank you :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)