String to Double Conversion without using strtod() or atof()

Reply

Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: String to Double Conversion without using strtod() or atof()

 
0
  #11
Nov 26th, 2008
If strtod() works on target with a non-null pointer, then a simple wrapper function would save you an awful lot of re-inventing the wheel.

Oh, and file a bug report with the library maintainer as well. A NULL parameter for the endptr is valid.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 7
Reputation: JCasso is an unknown quantity at this point 
Solved Threads: 0
JCasso JCasso is offline Offline
Newbie Poster

Re: String to Double Conversion without using strtod() or atof()

 
0
  #12
Nov 28th, 2008
Very well...

After some e-mail traffic with the company, I am shocked with an odd answer. The pos terminal I am working on does not support double or float variable types

But I have to use them and I cannot find any solution except re-inventing the wheel. (The one who invented wheel didn't have a deadline I guess )
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: String to Double Conversion without using strtod() or atof()

 
0
  #13
Nov 28th, 2008
Makes sense really, you don't want floating point anywhere near currency.

If you've got a decimal point to deal with, then consider
dollars = strtoul( p, 10, &endp );
cents = strtoul( endp+1, 10, NULL );
amount = dollars * 100 + cents;

A nice integer, which isn't going to suffer from rounding errors.
So long as you use a 4-byte int thoughout, then overflow isn't likely to be a problem for most reasonable currencies not experiencing hyper inflation.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 7
Reputation: JCasso is an unknown quantity at this point 
Solved Threads: 0
JCasso JCasso is offline Offline
Newbie Poster

Re: String to Double Conversion without using strtod() or atof()

 
0
  #14
Nov 28th, 2008
Right but it was only that easy if i wouldn't need to use 4 operations ( * / - + ) All except division will not cause much problem I guess.
Last edited by JCasso; Nov 28th, 2008 at 11:46 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: String to Double Conversion without using strtod() or atof()

 
0
  #15
Nov 28th, 2008
Originally Posted by JCasso View Post
Very well...

After some e-mail traffic with the company, I am shocked with an odd answer. The pos terminal I am working on does not support double or float variable types

But I have to use them and I cannot find any solution except re-inventing the wheel. (The one who invented wheel didn't have a deadline I guess )
Did you remember "FPU?" line in my post above? FPU means "Floating-Point Unit"...
Look at SoftFloat library:
http://www.jhauser.us/arithmetic/SoftFloat.html
Have you any OS on your POS? Sometimes OS supports FP emulation. Old C compilers for MS-DOS, for example, supported emulated floating-points arithmetics.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 7
Reputation: JCasso is an unknown quantity at this point 
Solved Threads: 0
JCasso JCasso is offline Offline
Newbie Poster

Re: String to Double Conversion without using strtod() or atof()

 
0
  #16
Nov 28th, 2008
I totaly forgat it sorry... Seems like this device does not have it.

About OS... You mean a known one? dont you? No this is a taiwan stuff
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: String to Double Conversion without using strtod() or atof()

 
0
  #17
Nov 28th, 2008
My old good POS was from Singapore . It was x86 16-bit processor so I have installed DR-DOS. My type Money was unsigned long (32-bit emulation). It's funny but it was CPU with FPU.
Don't worry: the divide op is not the most essential one in POS control program...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC