1<?php
2$number = 23.325;
3
4// english notation (default)
5$english_format_number = number_format($number);
6
7echo $english_format_number;
8//Publisher name - Bathila Sanvidu Jayasundara
9?>
1$price = 1234.44;
2
3$whole = intval($price); // 1234
4$decimal1 = $price - $whole; // 0.44000000000005 uh oh! that's why it needs... (see next line)
5$decimal2 = round($decimal1, 2); // 0.44 this will round off the excess numbers
6$decimal = substr($decimal2, 2); // 44 this removed the first 2 characters
7
8if ($decimal == 1) { $decimal = 10; } // Michel's warning is correct...
9if ($decimal == 2) { $decimal = 20; } // if the price is 1234.10... the decimal will be 1...
10if ($decimal == 3) { $decimal = 30; } // so make sure to add these rules too
11if ($decimal == 4) { $decimal = 40; }
12if ($decimal == 5) { $decimal = 50; }
13if ($decimal == 6) { $decimal = 60; }
14if ($decimal == 7) { $decimal = 70; }
15if ($decimal == 8) { $decimal = 80; }
16if ($decimal == 9) { $decimal = 90; }
17
18echo 'The dollar amount is ' . $whole . ' and the decimal amount is ' . $decimal;
1
2<?php
3
4$number = 1234.56;
5
6// english notation (default)
7$english_format_number = number_format($number);
8// 1,235
9
10// French notation
11$nombre_format_francais = number_format($number, 2, ',', ' ');
12// 1 234,56
13
14$number = 1234.5678;
15
16// english notation without thousands separator
17$english_format_number = number_format($number, 2, '.', '');
18// 1234.57
19
20?>
21
22