Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1646

NumberUtils fails to create requested type for floating point zero

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Trivial
    • Resolution: Fixed
    • 3.12.0
    • 3.13.0
    • lang.math.*
    • None

    Description

      This currently fails:

              assertEquals(Float.valueOf(0), NumberUtils.createNumber("0F"));
              assertEquals(Double.valueOf(0), NumberUtils.createNumber("0D"));
      

      This passes:

              assertEquals(Float.valueOf(0), NumberUtils.createNumber("0.F"));
              assertEquals(Double.valueOf(0), NumberUtils.createNumber("0.D"));
              assertEquals(Float.valueOf(0), NumberUtils.createNumber("0e0F"));
              assertEquals(Double.valueOf(0), NumberUtils.createNumber("0e0D"));
      

      This is due to the incorrect extraction of the mantissa for a floating point value when there is no exponent or decimal place as it includes the trailing format specifier (F or D). The input string is then not detected as being all zeros and the returned type is BigDecimal.

      Attachments

        Activity

          People

            aherbert Alex Herbert
            aherbert Alex Herbert
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: