#1
  1. No Profile Picture
    bag
    Guest
    Devshed Newbie (0 - 499 posts)
    anyone know how to round unsing perl. I need to truncate my price to the nearest cent. I need to format the output as a dollar price. I know how to add the dollar sign, I need to make it so I always have two decimal places.
  2. #2
  3. No Profile Picture
    Imo
    Guest
    Devshed Newbie (0 - 499 posts)
    perldoc -f printf

    printf("%.f2n",$var);

    Try that or something like it.
  4. #3
  5. No Profile Picture
    AjayLulia
    Guest
    Devshed Newbie (0 - 499 posts)
    I have a Best way in which u will get acrute result:

    I have used some thing like this
    Connect to any backend database for Eg ORACLE, use this Statement
    "Select round($varname) from dual"
    and then fetch the row.

    you will get Proper result.

    The other way is to use MATH Module
    Available with perl check in lib directory.

    I think this will help u

    ------------------
    Ajay Lulia.

  6. #4
  7. No Profile Picture
    bag
    Guest
    Devshed Newbie (0 - 499 posts)
    got it working.

    $formattedTotal=sprintf("$%.2f",$totalPX);

    that did the trick. It added a $ to the front and truncated to the nearest cent.

    thanks for your help everyone.
  8. #5
  9. No Profile Picture
    Imo
    Guest
    Devshed Newbie (0 - 499 posts)
    depends how accurate you want to be I guess!

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo