Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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 :: logout in php 
Php :: showing php code in browser 
Php :: php remove last 3 letters from string 
Php :: capitalize php 
Php :: laravel validation unique if this field is changed 
Php :: e_notice in php 
Php :: To find out where your php.ini is located 
Php :: Laravel Validation error message in blade or view 
Php :: convert multi-dimensional array into a single array in laravel 
Php :: laravel object to array 
Php :: php sort reverse 
Php :: larave artisan command run in web 
Php :: redirect back with input laravel in request 
Php :: how-to-call-ajax-in-wordpress 
Php :: laravel sortby varchar date 
Php :: laravel rule unique ignore 
Php :: php remove stop words from string 
Php :: php show active page 
Php :: add 1 day php datetime 
Php :: require_once php 
Php :: php requuire once 
Php :: php export excel 
Php :: yii2 activeform 
Php :: php sort array of array by key 
Php :: display custom post type 
Php :: php curl_exec get response json 
Php :: cakephp 2.x join 
Php :: php get keys and values from array 
Php :: symfony doctrine existing database 
Php :: session cakephp 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =