PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old January 17th, 2013, 12:35 AM
Catacaustic's Avatar
Catacaustic Catacaustic is offline
Code Monkey V. 0.9
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2005
Location: A Land Down Under
Posts: 1,898 Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 19 h 4 m 31 sec
Reputation Power: 1798
What you need to do is store the value in the database in a DECIMAL column. When a user enters the number, check it with is_numeric() to see if it's a numeric value or not. You can even use floatval() to convert the value to a number. When you display it, use number_format() and it will display the number just how you want it to.

Reply With Quote
  #17  
Old January 17th, 2013, 01:12 AM
newtonperri newtonperri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 40 newtonperri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 36 sec
Reputation Power: 1
Quote:
Originally Posted by drumn4life0789
I guess I don't understand what is really going on here.

Seems to me that all that needs to be done is strip out anything that is not a number or a decimal. Then check to make sure that there is only one decimal in the string. Then you check that if there is a decimal that there is only two digits behind it.

if we get all that as true we have a valid input. But since it is money I would say you throw it back to the user and ask if this is correct. And format it like so in the display, so that it is easy for the user to read
$###,###.##

Yes, but cant find how to do.
This does it but leaves the dot also for thousand, this gives me 1.100.50 when I need 1000.50
$price = '1.010.10';
$price = preg_replace("/[^0-9\.]/", "",$price);
and the filters, think arent using ok, maybe this is what I need however I doesnīt do it correctly:
$var = filter_var($price,FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
echo $var;
Thanks

Reply With Quote
  #18  
Old January 17th, 2013, 03:45 AM
newtonperri newtonperri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 40 newtonperri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 36 sec
Reputation Power: 1
Quote:
Originally Posted by Catacaustic
What you need to do is store the value in the database in a DECIMAL column. When a user enters the number, check it with is_numeric() to see if it's a numeric value or not. You can even use floatval() to convert the value to a number. When you display it, use number_format() and it will display the number just how you want it to.


I am trying, but this and everything I do for 1.010.00 returns 1.01
as 1.010 is one number as gW said, so as there are 2 numbers in 1.010.00 what should I do, split them, delete the dot.
I am lost, as they may fill in the form many ways 1.000.10 and 1000.10 should end both 1000.10 and 1000 should end 1000.00

The only dot acceptable is a dot for decimals, and if none a .00 should be added.

Reply With Quote
  #19  
Old January 17th, 2013, 07:07 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,907 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Month 1 Day 2 h 8 m 27 sec
Reputation Power: 581
I am not a regex expert (ask on the regex forum) but I'm sure there is an expression that can strip out all non-numerics except the last decimal, if it exists.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #20  
Old January 17th, 2013, 07:25 AM
newtonperri newtonperri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 40 newtonperri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 36 sec
Reputation Power: 1
Quote:
Originally Posted by gw1500se
I am not a regex expert (ask on the regex forum) but I'm sure there is an expression that can strip out all non-numerics except the last decimal, if it exists.

thanks will do that, didnīt know there was a special forum for that.

Reply With Quote
  #21  
Old January 18th, 2013, 08:59 AM
newtonperri newtonperri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 40 newtonperri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 36 sec
Reputation Power: 1
Doing this I manage to convert the empty value for field decimal to 0, filling in the form field price 2 and field decimal leave it emtpy the echo echo $holidaycost; before the ctype_digit check prints correctly 2.0 but after the ctype_digit check it prints the value empty....
I need to validate the field decimal.
PHP Code:
 $price htmlspecialchars($_POST['price']);
       
$decimal htmlspecialchars($_POST['decimal']);;
if (empty(
$decimal)) {
$decimal ='0';
 
$holidaycost $price.".".$decimal;
 echo 
$holidaycost;
echo 
"<br>";
 }
 if ( 
ctype_digit($_POST['price'])&& ctype_digit($_POST['decimal'])) {
 
$holidaycost $price.".".$decimal;
 echo 
"test $holidaycost";    
 } 

Reply With Quote
  #22  
Old January 18th, 2013, 10:04 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,907 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Month 1 Day 2 h 8 m 27 sec
Reputation Power: 581
PHP Code:
 $holidaycost $_POST['price'].".".$_POST['decimal']; 

Reply With Quote
  #23  
Old January 18th, 2013, 11:52 AM
newtonperri newtonperri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 40 newtonperri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 36 sec
Reputation Power: 1
Quote:
Originally Posted by gw1500se
PHP Code:
 $holidaycost $_POST['price'].".".$_POST['decimal']; 


Thanks, it didnīt work, but this did:
PHP Code:
if ( ctype_digit($_POST['price'])&& ctype_digit($decimal)) { 

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Price in form-input with format 0000.00

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap