Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4878207

request for new numeric methods round and truncate

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.4.0
    • core-libs
    • x86
    • windows_nt

      Name: nt126004 Date: 06/12/2003


      A DESCRIPTION OF THE REQUEST :
      I am requesting that 2 new methods be added.
      They should be applicable to any numeric type
      (including primitives) which contain both an
      integer and decimal portion, e.g. double, Double,
      etc. The methods could be added to java.lang.Math.

      The methods are:

      round(n,d) where n is the number to round and d
      is the number of positions after the decimal point.

      Unlike the current java.lang.Math.round() method
      (a) The return type should be the same as the input type.
          That is round(double,d) should return a double, not a long.
      (b) the rounding position is variable.

      If n is 0 then the number is rounded to the nearest
      integer. If n is less than 0 then the number is
      rounded to the nearest power of 10.
      e.g.
      round(123.4567,2) returns 123.46
      round(123.4567,0) returns 123
      round(123.4567,-1) returns 120

      ****

      truncate(n,d) where n is the number to truncate and d
      is the number of positions after the decimal point.

      The return type should be the same as the input type.

      If n is 0 then the number is truncated to the nearest
      integer. If n is less than 0 then the number is
      truncated to the nearest power of 10.
      e.g.
      truncate(123.4567,2) returns 123.45 (no rounding)
      truncate(123.4567,0) returns 123
      truncate(123.4567,-1) returns 120

        

      JUSTIFICATION :
      good to have
      (Review ID: 187124)
      ======================================================================
      ###@###.### 10/28/04 01:09 GMT

            darcy Joe Darcy
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: