DBookatay Posted September 12, 2007 Share Posted September 12, 2007 I have a form that uses dollar increments in several different input fields. I need help so that if a user does not add a "." the form will automatically do it form them before the form is inserted into the dB. Meaning, if the field is: $100.00, and the user only types "$100," the form will do the rest. And if the user types :"$100.00" nothing will happen... Some of the fields in the form are: sold_price = '$_POST[sold_price]', tax = '$_POST[tax]', doc = '$_POST[doc]', reg = '$_POST[reg]', down = '$_POST[down]', rate = '$_POST[rate]', pymtAmt = '$_POST[pymtAmt]', Any help would be awesome... Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 12, 2007 Share Posted September 12, 2007 http://php.net/number_format Quote Link to comment Share on other sites More sharing options...
DBookatay Posted September 15, 2007 Author Share Posted September 15, 2007 Does anyone have a working example? I've read http://us.php.net/number_format, but it doesn't explain how to do what I want to accomplish. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 $totalamount=number_format($totalamount, '.'); Quote Link to comment Share on other sites More sharing options...
DBookatay Posted September 15, 2007 Author Share Posted September 15, 2007 $totalamount=number_format($totalamount, '.'); I tried your code, but it puts commas into the post, which will pose a problem. Is there another way to do it? $soldAmt = number_format($_POST['soldAmt'], '.'); Quote Link to comment Share on other sites More sharing options...
DBookatay Posted September 15, 2007 Author Share Posted September 15, 2007 I tried your code, but it puts commas into the post, which will pose a problem. Is there another way to do it? $soldAmt = number_format($_POST['soldAmt'], '.'); Anyone? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 Will not work: $soldAmt = number_format($_POST['soldAmt'], '.'); ); Will work: <?php $soldAmt = $_POST['soldamt']; $soldAmt = number_format($soldamt,'.');?> Quote Link to comment Share on other sites More sharing options...
DBookatay Posted September 15, 2007 Author Share Posted September 15, 2007 It's still adding comma's Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 doesnt help can you show me what it is doing? ??? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 made some adjustments <?php $soldAmt = number_format($soldamt,2,'.',' ');?> should out put $100.00 Quote Link to comment Share on other sites More sharing options...
DBookatay Posted September 15, 2007 Author Share Posted September 15, 2007 made some adjustments <?php $soldAmt = number_format($soldamt,2,'.',' ');?> should out put $100.00 Almost there... It is doing what I need, but its adding a space: I typed 1200, and it outputed 1 200.00 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 take ' ' out and the last comma problem solved Quote Link to comment Share on other sites More sharing options...
DBookatay Posted September 15, 2007 Author Share Posted September 15, 2007 take ' ' out and the last comma problem solved $soldamt = $_POST['soldAmt']; $soldAmt = number_format($soldamt,2,'.'); Now nothing gets outputted Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 ok put it back and now put <?php $totalamt=trim($totalamt); /// will remove whitespace ?> Quote Link to comment Share on other sites More sharing options...
jitesh Posted September 15, 2007 Share Posted September 15, 2007 <?php $number = 1234; echo $english_format_number = number_format($number, 2, '.', ''); ?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 oh my bad it should be '' not ' ' Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 should work right: <?php $totalamt=number_format($totalamt ,2, '.', '');?> 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.