andyhajime Posted February 15, 2008 Share Posted February 15, 2008 Hi guys, I'm looking for a function to add 2 decimal point from a non-decimal number. what function do i use to change 676865 to 6768.65. I've use sprintf("%.2f","676865") but I get is 676865.00. some dude elsewhere says to use "number_format($number,[number of decimal places]);" but I gotten 676,865.00 instead. Any ideas? Link to comment https://forums.phpfreaks.com/topic/91202-how-do-i-add-decimal-point-to-a-number/ Share on other sites More sharing options...
mem0ri Posted February 15, 2008 Share Posted February 15, 2008 Wouldn't $x /= 100; work? So long as you're not hard-typed to an integer, it should auto-convert to a float. (at least it always does for me) Link to comment https://forums.phpfreaks.com/topic/91202-how-do-i-add-decimal-point-to-a-number/#findComment-467429 Share on other sites More sharing options...
andyhajime Posted February 15, 2008 Author Share Posted February 15, 2008 IT WORKS! My gosh...! That's the most simplest and I kept thinking of floats all this time. Thanks! Link to comment https://forums.phpfreaks.com/topic/91202-how-do-i-add-decimal-point-to-a-number/#findComment-467431 Share on other sites More sharing options...
rameshfaj Posted February 15, 2008 Share Posted February 15, 2008 That was the simplest method for ur requirement.But u should first determine whether the number is float or integer value. Link to comment https://forums.phpfreaks.com/topic/91202-how-do-i-add-decimal-point-to-a-number/#findComment-467564 Share on other sites More sharing options...
andyhajime Posted March 31, 2008 Author Share Posted March 31, 2008 That was the simplest method for ur requirement.But u should first determine whether the number is float or integer value. The simples method is the best method. I'm actually looking for a quick solution so I can get the coding done. Besides, I really don't like a very long lined coding. They normally confuses me. Link to comment https://forums.phpfreaks.com/topic/91202-how-do-i-add-decimal-point-to-a-number/#findComment-505759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.