Logo

Programming-Idioms

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

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.

import "fmt"
s := fmt.Sprintf("%.2f", x)
#include <stdio.h>
sprintf(s, "%.2f", x);

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