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? 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? 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 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); 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. 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 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
Archived
This topic is now archived and is closed to further replies.