DEVILofDARKNESS Posted April 21, 2009 Share Posted April 21, 2009 How can I make From a random number like 1,0383 => 1? Examples: 2,00001 => 2 2,9992 => 2 It just always has to become the first whole number under the number itself. My question is how should I program it in php? I know how you make it a float point? but then 2,998 will become 3 :-s Quote Link to comment https://forums.phpfreaks.com/topic/155087-solved-decimal-problem/ Share on other sites More sharing options...
Maq Posted April 21, 2009 Share Posted April 21, 2009 How is this number generated? If it's a number in a string it's as simple as: $var = '2,340'; echo $var[0]; Quote Link to comment https://forums.phpfreaks.com/topic/155087-solved-decimal-problem/#findComment-815737 Share on other sites More sharing options...
The Little Guy Posted April 21, 2009 Share Posted April 21, 2009 $string = '2,00001'; echo $string{0}; Quote Link to comment https://forums.phpfreaks.com/topic/155087-solved-decimal-problem/#findComment-815738 Share on other sites More sharing options...
soak Posted April 21, 2009 Share Posted April 21, 2009 if 2,998 is 2.998 (i.e. nearly three) then you can use floor($number) Quote Link to comment https://forums.phpfreaks.com/topic/155087-solved-decimal-problem/#findComment-815753 Share on other sites More sharing options...
The Little Guy Posted April 21, 2009 Share Posted April 21, 2009 actually I would use intval <?php echo intval('4,20000000000000000000'); echo '<br>'; echo intval('420,000000000000000000'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/155087-solved-decimal-problem/#findComment-815762 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.