If you want to get around the rounding errors with javascript then you need to work in cents (or even hundreths of a cent for more accuracy).
So basically multiply your currency like dollars by 100 to get it into cents, do your calculations, then finally, divide by 100 or simply sprintf to display in dollars By using non-fractional numbers, the javascript IEEE 754 floating point operations are exact. Alternatively you could try a decimal or BigNumber implementation in javascript, a couple are mentioned in http://stackoverflow.com/a/3439981 Jeff On Friday, 13 July 2012 05:29:59 UTC-5, Micheil Smith wrote: > > Hi Eysenck, > > You may not want to use Node.js (or any javascript vm) for this, due to > the inherent issues > javascript has dealing with fractional numbers, for instance, take the > classic expression: > > "0.3 - 0.2 != 0.1" > > However, as this is a financial application, you'd probably be storing > currency as an integer, > not as a float, so you wouldn't have this issue. (ie, store all currency > in the lowest fractional, > so $19.35 is stored as 1935). > > As for choosing your web framework, you'll definitely want to make sure > that the framework > is either battle tested or built to a good standard (ie, it'd suck if you > had mass-insertion issues > in your DB, or if your app crashed and you lost all state of accounts.) > > > So, the TL;DR; of this is: You could probably use node.js + express for > this, but, you'll want to > make sure you know node.js first, before jumping down this chasm. You may > just be better off > using the stack of technologies you already know. > > Kind Regards, > Micheil Smith > -- > BrandedCode.com > > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
