English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2006-12-20 14:59:56 · 4 answers · asked by thnbgr1 1 in Computers & Internet Programming & Design

and the round function isn't suitable because I need it to cut off, not round.

2006-12-20 15:11:16 · update #1

4 answers

If you want to remove everything after and including the decimal, use:
$newnumber = substr($number, 0, strpos($number, "."));
substr takes three values:
$number, which is the number or a variable with the number
0, which will be the start of the number
strpos($number,"."), which tells substr how far to cut off, which here you are using strpos to tell it how far in the '.' is

If you need more help, you may want to look at the online manual.

2006-12-20 15:11:30 · answer #1 · answered by Bryan A 5 · 1 0

The round() function should be enough.

2006-12-20 23:05:56 · answer #2 · answered by Kevin H 2 · 0 0

try using number_format() function.

string number_format ( float number [, int decimals [, string dec_point, string thousands_sep]] )

number_format() returns a formatted version of number

2006-12-20 23:29:07 · answer #3 · answered by Cva 2 · 0 0

What you want to do is called "truncate". Cast your variable - (integer)$myVal or use the intval($myVar) function.

You might want to bookmark http://www.php.net.

2006-12-20 23:46:35 · answer #4 · answered by Grant P 2 · 0 0

fedest.com, questions and answers