Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove the numbers and keep the rest after the dot

Tags:

php

Sorry I couldn't explain clearly in the title. I Studied math in other language I don't know what it calls.

I have these values.

$input = 13.2156;
$input = 45.232;
$input = 1193.215624;

I want a function in PHP to get what what after the dot, which is this case

$input = 13.2156;     // 0.2156
$input = 45.232;      // 0.232
$input = 1193.215624; // 0.215624

I know intval() do the opposite. BUT I want the opposite of the opposite. :D

like image 587
Abdullah Salma Avatar asked Mar 11 '13 18:03

Abdullah Salma


2 Answers

$input = $input - intval($input);

For negative numbers, the above code will get a negative decimal component (which may be desired in some cases). If you always want the positive decimal component, just take the absolute value of $input.

like image 191
Tushar Avatar answered Sep 22 '22 18:09

Tushar


Try $input = $input - intval($input).

This leaves just the fraction.

like image 37
RouteMapper Avatar answered Sep 22 '22 18:09

RouteMapper