djbuddhi Posted September 22, 2009 Share Posted September 22, 2009 Guys ; my variable is 100,100.00 but i want to use as 10000 i want to omit , in a php variable ....how to do that ? whats the command that is used 2 display as it is thx Link to comment https://forums.phpfreaks.com/topic/175096-solved-how-to-omit-q-varibale-in-a-php-code/ Share on other sites More sharing options...
ozestretch Posted September 22, 2009 Share Posted September 22, 2009 number_format() Link to comment https://forums.phpfreaks.com/topic/175096-solved-how-to-omit-q-varibale-in-a-php-code/#findComment-922848 Share on other sites More sharing options...
djbuddhi Posted September 22, 2009 Author Share Posted September 22, 2009 no no i want 2 remove the , from the variable ... Link to comment https://forums.phpfreaks.com/topic/175096-solved-how-to-omit-q-varibale-in-a-php-code/#findComment-922868 Share on other sites More sharing options...
trq Posted September 22, 2009 Share Posted September 22, 2009 no no i want 2 remove the , from the variable ... Exactly. Link to comment https://forums.phpfreaks.com/topic/175096-solved-how-to-omit-q-varibale-in-a-php-code/#findComment-922871 Share on other sites More sharing options...
ozestretch Posted September 22, 2009 Share Posted September 22, 2009 my variable is 100,100.00 but i want to use as 10000 i want to omit , in a php variable ....how to do that ? <?php echo number_format('100,100.00', 2, '', ''); // Prints 10000 ?> Link to comment https://forums.phpfreaks.com/topic/175096-solved-how-to-omit-q-varibale-in-a-php-code/#findComment-922872 Share on other sites More sharing options...
thebadbad Posted September 22, 2009 Share Posted September 22, 2009 my variable is 100,100.00 but i want to use as 10000 i want to omit , in a php variable ....how to do that ? <?php echo number_format('100,100.00', 2, '', ''); // Prints 10000 ?> LOL, that's only because the string 100,100.00 is typecasted into the float 100 (to respect what number_format() expects), resulting in 10000 because of the 2 decimals and no decimal point. @OP I'm not sure what you actually meant, but you can remove every comma from a string with str_replace(): echo str_replace(',', '', '100,100.00'); //100100.00 Or reformat the number with number_format(), removing decimals (rounding) and thousands separator: $float = (float) str_replace(',', '', '100,100.00'); echo number_format($float, 0, '.', ''); Link to comment https://forums.phpfreaks.com/topic/175096-solved-how-to-omit-q-varibale-in-a-php-code/#findComment-922895 Share on other sites More sharing options...
ozestretch Posted September 23, 2009 Share Posted September 23, 2009 LOL, that's only because the string 100,100.00 is typecasted into the float 100 (to respect what number_format() expects), resulting in 10000 because of the 2 decimals and no decimal point. he asked to convert my variable is 100,100.00 but i want to use as 10000 100,100.00 = 10000 Even by removing decimal and comma, he would be left with 100100 Link to comment https://forums.phpfreaks.com/topic/175096-solved-how-to-omit-q-varibale-in-a-php-code/#findComment-923209 Share on other sites More sharing options...
djbuddhi Posted September 23, 2009 Author Share Posted September 23, 2009 wow this string replace thing is works fine ....thanks guys Link to comment https://forums.phpfreaks.com/topic/175096-solved-how-to-omit-q-varibale-in-a-php-code/#findComment-923265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.