Converting scientific notation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Skeleton Man

    Converting scientific notation

    Hi,

    I have a script that generates numbers beyond the range of it, and so it's
    throwing them out as scientfic notation (e.g. 5E+10 instead of
    50,000,000,000) . The only way I've found of avoiding this is by using bc*()
    functions in place of normal operators (e.g. bcmul() instead of '*').
    Surely there's a way to simply convert a number in scientific notation into
    a normal integer ?

    Regards,
    Chris


  • Tony Marston

    #2
    Re: Converting scientific notation

    This is what I use to convert float|real|doub le values into display format:

    $float = sprintf('%f', $fieldvalue);
    $integer = sprintf('%d', $fieldvalue);
    if ($float == $integer) {
    // this is a whole number, so remove all decimals
    $output = $integer;
    } else {
    // remove trailing zeroes from the decimal portion
    $output = rtrim($float,'0 ');
    } // if

    HTH.

    --
    Tony Marston

    This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




    "Skeleton Man" <invalid@guestw ho.com> wrote in message
    news:ZZiVc.276$ D7.209@news-server.bigpond. net.au...[color=blue]
    > Hi,
    >
    > I have a script that generates numbers beyond the range of it, and so it's
    > throwing them out as scientfic notation (e.g. 5E+10 instead of
    > 50,000,000,000) . The only way I've found of avoiding this is by using
    > bc*()
    > functions in place of normal operators (e.g. bcmul() instead of '*').
    > Surely there's a way to simply convert a number in scientific notation
    > into
    > a normal integer ?
    >
    > Regards,
    > Chris
    >
    >[/color]


    Comment

    • Skeleton Man

      #3
      Re: Converting scientific notation

      >This is what I use to convert float|real|doub le values into display format:
      [color=blue]
      >$float = sprintf('%f', $fieldvalue);
      >$integer = sprintf('%d', $fieldvalue);
      >if ($float == $integer) {
      > // this is a whole number, so remove all decimals
      > $output = $integer;
      >} else {
      > // remove trailing zeroes from the decimal portion
      > $output = rtrim($float,'0 ');
      >} // if[/color]

      That works brilliantly, thankyou !

      Regards,
      Chris


      Comment

      Working...