Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php echo number with decimal


<?php

$number = 1234.56;

// english notation (default)
$english_format_number = number_format($number);
// 1,235

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

$number = 1234.5678;

// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57

?>

Comment

how to get only decimal value in php

$price = 1234.44;

$whole = intval($price); // 1234
$decimal1 = $price - $whole; // 0.44000000000005 uh oh! that's why it needs... (see next line)
$decimal2 = round($decimal1, 2); // 0.44 this will round off the excess numbers
$decimal = substr($decimal2, 2); // 44 this removed the first 2 characters

if ($decimal == 1) { $decimal = 10; } // Michel's warning is correct...
if ($decimal == 2) { $decimal = 20; } // if the price is 1234.10... the decimal will be 1...
if ($decimal == 3) { $decimal = 30; } // so make sure to add these rules too
if ($decimal == 4) { $decimal = 40; }
if ($decimal == 5) { $decimal = 50; }
if ($decimal == 6) { $decimal = 60; }
if ($decimal == 7) { $decimal = 70; }
if ($decimal == 8) { $decimal = 80; }
if ($decimal == 9) { $decimal = 90; }

echo 'The dollar amount is ' . $whole . ' and the decimal amount is ' . $decimal;
Comment

how to get a whole number from decimal in php

<?php 
$number = 23.325;

// english notation (default)
$english_format_number = number_format($number);

echo $english_format_number;
//Publisher name - Bathila Sanvidu Jayasundara
?>
Comment

PREVIOUS NEXT
Code Example
Php :: validation not exist in table laravel 
Php :: php move file to another directory 
Php :: php fix array keys 
Php :: validate user password laravel8 
Php :: Notice: Trying to access array offset on value of type int in /var/www/pdam/modules/phpexcel/PHPExcel/Cell/DefaultValueBinder.php on line 82 
Php :: migrations required field laravel 
Php :: file storage laravel 
Php :: how to call a helper function in blade 
Php :: get data from select option php 
Php :: debian php switch version 
Php :: utf8 php 
Php :: public_path laravel 
Php :: php if $_post 
Php :: laravel 8 foreign key migration 
Php :: codeigniter 3 or where not in 
Php :: how to print in php 
Php :: Clear php cache 
Php :: convert timestamp to date php 
Php :: laravel image path 
Php :: magento getcollection get first 
Php :: laravel where json contains 
Php :: password validation rules laravel 
Php :: laravel fixed character limit 
Php :: return view in laravel controller 
Php :: How to check if email exists in laravel validaton 
Php :: Passing PHP Arrays to JavaScript 
Php :: php artisan down allow ip 
Php :: is dir php 
Php :: remove element from xml on php 
Php :: php header redirect with parameters 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =