Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // sprintf — build a string $name = 'Alice'; $score = 97.5; $msg = sprintf('Player %s scored %.1f points', $name, $score); echo $msg; // Player Alice scored 97.5 points // Zero-padding integers (useful for dates/IDs) echo sprintf('Order #%05d', 42); // Order #00042 // printf — print directly printf('Price: $%.2f', 9.9); // Price: $9.90 // number_format(number, decimals, dec_point, thousands_sep) echo number_format(1234567.891, 2); // 1,234,567.89 echo number_format(1234567.891, 2, '.', ','); // 1,234,567.89 echo number_format(1234567.891, 2, ',', '.'); // 1.234.567,89 (European)
Result
Open