- Home /
how to keep fraction number ???
hello
i have problem with keep the fraction numbers...
for example ...
var timeOne : float = 0.0;
timeOne = 100/250;
print(timeOne.ToString("f5"));
will be print 0.00000
also when i used as float 0.00
but must be 0.40000
note : i don't want to use the value as string but as float.
thx.....
Answer by Lovrenc · Jan 20, 2013 at 01:58 PM
100 is integer value. 250 is integer value.
Division of two integer valuse gives INTEGER VALUE! You wont get fractions naturally. Even though your variable is of type float, division is executed on integer values and then casted to float. But if you were to write:
timeOne = 100f/250f
you WOULD get fraction result.
That's one of the most common mistakes arcoss all program$$anonymous$$g languages ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613091243im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
getting a sum from two scripts 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Maths issue + Null reference error? -1 Answers