kjtocool Posted January 3, 2008 Share Posted January 3, 2008 Can I use substr() on numerical float variables? For example, if I have 9.33333333333333333333333333333333333333 repeating, and I want to only keep the first 5 characters (including decimal point), how do I go about doing so? Quote Link to comment https://forums.phpfreaks.com/topic/84311-solved-how-do-i-shorten-a-number/ Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Do you want any rounding? Quote Link to comment https://forums.phpfreaks.com/topic/84311-solved-how-do-i-shorten-a-number/#findComment-429347 Share on other sites More sharing options...
kjtocool Posted January 3, 2008 Author Share Posted January 3, 2008 That's a good question. I suppose yes I do. Example: 9.126709098 I would want: 9.127 Quote Link to comment https://forums.phpfreaks.com/topic/84311-solved-how-do-i-shorten-a-number/#findComment-429357 Share on other sites More sharing options...
Zane Posted January 3, 2008 Share Posted January 3, 2008 Well then, I'd say you should round() then echo round(9.126709098, 3); Quote Link to comment https://forums.phpfreaks.com/topic/84311-solved-how-do-i-shorten-a-number/#findComment-429383 Share on other sites More sharing options...
kjtocool Posted January 3, 2008 Author Share Posted January 3, 2008 Yep, that's exactly what I was looking for. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/84311-solved-how-do-i-shorten-a-number/#findComment-429390 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 I dont think that will give you just five digits, it will just give you 3 after the decimal. So you'll still get 123123123.123 Quote Link to comment https://forums.phpfreaks.com/topic/84311-solved-how-do-i-shorten-a-number/#findComment-429398 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.