Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Perl

Idiom #23 Convert real number to string with 2 decimal places

Given a real number x, create its string representation s with 2 decimal digits following the dot.

$s = sprintf "%.2f", $x;
#include <stdio.h>
sprintf(s, "%.2f", x);

New implementation...
< >
programming-idioms.org