Logo

Programming-Idioms

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

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.

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

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