get this from my database:
252.587254564
Well i wanna remove the .587254564
and keep the 252
, how can i do that?
What function should i use and can you show me an example?
Greetings
Rather than rounding, how would I remove the decimal notation from this number? floor(17.672); floor() makes it stay as a float, so mark's solution below (same as intval(17.672) ) might be better. echo round(10.5); // Round the number, this example would echo 11.
The round() function rounds a floating-point number. Tip: To round a number UP to the nearest integer, look at the ceil() function. Tip: To round a number DOWN to the nearest integer, look at the floor() function.
String truncated = String. valueOf((int) doubleValue); We can confidently use this approach when we're guaranteed that the double value is within the range of an int.
$num + 0 does the trick.
You can do it in PHP:
round($val, 0);
or in your MYSQL statement:
select round(foo_value, 0) value from foo
You can do a simply cast to int
.
$var = 252.587254564; $var = (int)$var; // 252
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With