Kevin Harrison
Kevin Harrison

Reputation: 337

Format number to not have decimals

Lets say the variable $number holds a decimal like 16.66677666777

How would I make it echo $number and just say 16 rather than 16.66677666777?

Upvotes: 0

Views: 119

Answers (6)

qwertmax
qwertmax

Reputation: 3450

Just use inval function

http://php.net/manual/en/function.intval.php

 $number = 16.66677666777;
 echo intval($number); //16

Upvotes: 1

kasper Taeymans
kasper Taeymans

Reputation: 7026

you could also use floor()

echo floor(16.66677666777); 

Upvotes: 1

Armin
Armin

Reputation: 15938

You could cast it to an integer:

echo (int) $number;

or using intval:

echo intval($number);

Or you could use the mathematic function floor to round the number down.

echo floor($number);

This function keep the variable type float.

Here you'll find a small example: http://codepad.org/4um8gJSi

Upvotes: 1

MD SHAHIDUL ISLAM
MD SHAHIDUL ISLAM

Reputation: 14523

Just use intval function

$number = 16.66677666777;

$number = intval($number);

Upvotes: 1

Arun Kumar M
Arun Kumar M

Reputation: 848

echo intval(2.0000); //2

See this

Upvotes: 1

This will suffice.

<?php
$number=16.66677666777;
echo (int)$number; //16

Upvotes: 1

Related Questions