What I want to adjust is the precision of the float that is written. Like this i get 8 digits after the ".". Is there anything like setprecision from C++ to limit the digits?
QUOTE(gentlesea @ 01/09/09, 06:25 PM) [snapback]298563[/snapback] What I want to adjust is the precision of the float that is written. Like this i get 8 digits after the ".". Is there anything like setprecision from C++ to limit the digits? Cheers.
Not really, you need to do the round manually. Its not evry hard to do tough.
Thank you very much for the answer. There is one little glitch in your solution. If the value is a negative 0 with fraction, e.g. -0.1234 then your routing loses the - with the 0 when casting to int. Also $ret = $ret + (abs((int) $c)); was adjusted, because otherwise a lot of - are copied when using negative floats.
CODE global proc string getStringOfFloatWithCertainToleranceDigits(float $float, int $tol) { $b = (int) $float; // does not save the minus when being 0 string $ret; if ($b == 0) { if ($float < 0) { $ret = "-" + $b; } else { $ret = $b; } } else { $ret = $b; } if ($tol > 0) $ret = $ret + "."; $c = $float; for ($i = 0; $i < $tol; $i++) { $c = (($c - (int) $c) * 10); $ret = $ret + (abs((int) $c)); } return $ret; }