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 Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 22, 2009 Share Posted September 22, 2009 number_format() Quote Link to comment 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 ... Quote Link to comment 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. Quote Link to comment 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 ?> Quote Link to comment 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, '.', ''); Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.