Jump to content

Count numbers after decimal point


Tjk

Recommended Posts

:) No it isn't.

Basically if the $sum has the value 2.333333444445555 then the script will do something like add so much to another variable. But if the value is only 2 then it will do something like takeaway so much to this other variable.

So far I've been unable to find a way of doing it.

Thanks for any help you can give me.
You can use the explode() function to get that. Here's a short example:
[code]<?php
$x = 3574/297;
echo $x.'<br>';
$y = explode('.',$x);
echo '<pre>' . print_r($y,true) . '</pre>';
echo 'The number of digits after the decimal point is: ' . strlen($y[1]);
?>[/code]

Ken
How would you distinguish between 2, 2.0, and 2.0000000000000000000, all of which have different numbers after the 2.

Perhaps you want to distinguish between a number that is an integer and one that isn't.

The ".. has so many numbers after a decimal point then do something else do something different" is just too vague.

Maybe Ken's solution is what you want. If not, explain clearly.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.