Re: Round floats to N decimal places?



You should consider if you want to work with Float, Integer, BigDecimal
(which is some kind of LongFloat) or Rational. Using Float for
something that needs to be rounded regularly to a fixed number of
digits after the decimal point may or may not be the right way to go,
because it has some behaviour in terms of rounding which has to be
considered.
There is a RubyForge-project long-decimal (
http://rubyforge.org/projects/long-decimal/ ) which will be specialized
for doing calculations with a defined number of digits after the
decimal point. Maybe this will be useful for the kind of calculations
you are trying to do.

.



Relevant Pages

  • Re: Floating Point Precision guidance.
    ... using 'float'. ... not 5 to 6 digits to the right of comma. ... those 5 digits precission are already used up with .5 ... or less complex calculations you cannot even count on the ...
    (alt.comp.lang.learn.c-cpp)
  • Re: converting float to double
    ... >> insists that I read the stock prices as float. ... >> Since everywhere else the system uses double to hold these prices, ... A 64 bit integer will correctly model currency to 18 digits (with ... float usnd = 8624231011335.27f * ...
    (comp.lang.c)
  • Re: converting float to double
    ... >> insists that I read the stock prices as float. ... >> Since everywhere else the system uses double to hold these prices, ... A 64 bit integer will correctly model currency to 18 digits (with ... In a mythical currency with 1,000,000 units per dollar, that would ...
    (comp.lang.c)
  • Re: converting float to double
    ... >> insists that I read the stock prices as float. ... >> Since everywhere else the system uses double to hold these prices, ... A 64 bit integer will correctly model currency to 18 digits (with ... calcuations in 110 digits of precision (so that things like interest ...
    (comp.lang.c)
  • Re: brand newbie function libraries
    ... Input section, Calculations, and Output. ... void print(const float& out){ ...
    (alt.comp.lang.learn.c-cpp)