Skrevet av Emne: Converting numbers to two decimal form in Perl  (Lest 4350 ganger)

ATC

  • Gjest
Converting numbers to two decimal form in Perl
« på: 27. ſeptember 2008, 18:24 pm »
  • [applaud]0
  • [smite]0
  • How to convert a numeric value to two digit form in Perl? Examples:
    "12" -- "12.00"
    "12.3" -- "12.30"
    "12.34" -- "12.34"
    "12.345" -- "12.34"



    ATC

    • Gjest
    [Solved] Converting numbers to two decimal form in Perl
    « Svar #1 på: 27. ſeptember 2008, 18:24 pm »
  • [applaud]0
  • [smite]0

  • $formatted = sprintf("%.2f",$unformatted);

    (Source: "perldoc -f sprintf")