S
Sajan
Hi
I am new to perl.
I have a problem with floating point arithmetic.
I am using a a variable $time_now which i want to increment by 0.001
everytime in a while loop until the $tot_time is equal to $time_now.
I am using
$accuracy = 0.001;
$time_now = 0.0;
$tot_time = 10.0;
while ($time_now <= $tot_time)
{
#couple of calculations based on $time_now;
$time_now = $time_now + $accuracy;
}
now the problem i am facing is
$time_now becomes 0.0019999999993, 0.0029999999993 etc
but for my calculations i expect only 0.001, 0.002 etc upto 10.0.
In short i dont expect such an accurate precision
Please let me know how to overcome this.
Thanking you for your help.
Sajan.
I am new to perl.
I have a problem with floating point arithmetic.
I am using a a variable $time_now which i want to increment by 0.001
everytime in a while loop until the $tot_time is equal to $time_now.
I am using
$accuracy = 0.001;
$time_now = 0.0;
$tot_time = 10.0;
while ($time_now <= $tot_time)
{
#couple of calculations based on $time_now;
$time_now = $time_now + $accuracy;
}
now the problem i am facing is
$time_now becomes 0.0019999999993, 0.0029999999993 etc
but for my calculations i expect only 0.001, 0.002 etc upto 10.0.
In short i dont expect such an accurate precision
Please let me know how to overcome this.
Thanking you for your help.
Sajan.