| | |
String to Double Conversion without using strtod() or atof()
![]() |
•
•
Join Date: Nov 2008
Posts: 7
Reputation:
Solved Threads: 0
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
)
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
) Makes sense really, you don't want floating point anywhere near currency.
If you've got a decimal point to deal with, then consider
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.
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.
•
•
•
•
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)
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.
![]() |
Other Threads in the C Forum
- Previous Thread: Pointer arrays and structures
- Next Thread: need help with validation
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop initialization input interest intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation owf pdf pointer pointers posix power probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi







. 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.