English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

how do I format a decimal number to ".000" without the leading 0 in front of the decimal point.

2006-11-01 15:42:26 · 2 answers · asked by aznskillz 2 in Computers & Internet Programming & Design

2 answers

$number = 0.98;
$formatted_number = number_format ($number, 3);
if (abs($number) < 1) {
$formatted_number = str_replace('0.', '.', $formatted_number);
}

This should set $formatted_number to ".980"...

2006-11-03 08:30:35 · answer #1 · answered by NC 7 · 0 0

use format_number to get the decimal place. den convert the decimal to string and substring it

2006-11-02 00:21:24 · answer #2 · answered by fang 4 · 0 0

fedest.com, questions and answers