home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource2 / sclib_2 / 2_2 / v6n2015a.txt < prev    next >
Encoding:
Text File  |  1995-11-01  |  393 b   |  22 lines

  1. /*  FROUNDL.C  Round float n
  2.  *  ~~~~~~~~~  to precision p,
  3.  *             return long = n * 10^p.
  4.  *             NOT copyrighted.
  5.  */
  6.  
  7. #include <math.h>
  8.  
  9. long froundl(n, p)
  10. double n;  /* Number to round */
  11. int p;  /* Precision */
  12. {
  13.     long r;  /* Rounded */
  14.  
  15.     r = (long)(n * pow(10.0,(double)(p+1)));
  16.     if ((r % 10L) > 4L)
  17.         r += 5L;
  18.     return(r / 10L);
  19. }
  20.  
  21.  
  22.