C++ floor() decreasing value by 1 -


I have repeatedly written this function to round a double in N digits :

  Double double double (double value, unsigned integer points) {if (value == 0.0) return value; String num = dtos (value); Size_t found = num.find ("."); String dc = ""; If (found! = String :: NPO) dec = num.substr (found + 1); Return value; If (dec.length () & lt; = points) {logfile ("c: \\ test.txt", "return:" + dtos (value) + "\ n \ n \ n"); return value; } Other {Double P10 = Pau (10, (dec.length () - 1)); LogtoFile ("C: \\ test.txt", "VALUE:" + DTOS (value) + "\ n"); Double child = value * p10; LogtoFile ("C: \\ test.txt", "MUL:" + DTOS (MUL) + "\ n"); Double zodiac = mul + 0.5; LogtoFile ("C: \\ test.txt", "SUM:" + Data (zodiac) + "\ n"); Double floors = floor (yoga); LogtoFile ("C: \\ test.txt", "floor:" + dotos (flooring) + "\ n"); Double div = Flord / P10; LogtoFile ("C: \\ test.txt", "div:" + dtos (div) + "\ n ------- \ n"); Return RoundDouble (div, number); }}  

But from the log file, in some cases something really strange with the floor () ...

Here is an example of a good calculation Is:

  VALUE: 2.0108 mül: 2010.8 SM: 2011.3 Floor: 2011 DIV: 2.011 ------- VALUE: 2.011 mül: 201.1 SM: 201.6 floor: 201 DIV: 2.01 - Here is an output example of bad calculation:  
  VALUE: 67.6 946 MUEL: 67694.6 SM: 67695.1 Floor: 67695 DIV: 67.695 ------- VALUE: 67.695 MUl: 676 9.5 SUM: 6770 Floor: 6769 & lt; = Problem here Divi: 67.6 9 ------- Returns: 67.69  

Do not have the floor (6770) 6770 is going to return? Why is it coming back to 6769?

First of all, thanks for suggestions, "Double to string -> string to double for BTW -> Flooring "solution is giving only an estimate result. So I just need to change:

  double floors = floor (yoga);  

with

  double floors = floor (studs (DTOS (yoga));  

If anyone has a better solution then post it.


Comments