This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 22306 - decimal math support
Summary: decimal math support
Status: RESOLVED INVALID
Alias: None
Product: WHATWG
Classification: Unclassified
Component: JavaScript (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 enhancement
Target Milestone: Unsorted
Assignee: Mathias Bynens
QA Contact: sideshowbarker+javascript
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-07 08:52 UTC by Jim Michaels
Modified: 2013-09-04 09:04 UTC (History)
1 user (show)

See Also:


Attachments

Description Jim Michaels 2013-06-07 08:52:50 UTC
I could suppose that there might not be the full support for the full range of Math. functions and constants for standard decimal math as found in implementations of decimal math classes in c++ etc as might be used to implement this (?). that is what I am seeing with the set of functions and methods available for that kind of data type, the actual set of functions supported is rather limited. perhaps it can be limited to some sort of standard subset of C++11 or future c++ standard library thing.

this is needed for financial calculations. as things are now, floating point error really messes up the numbers when you start getting to repeatedly adding and subtracting multiples of 0.11 and you get values like +/-0.009999999999999986
when you should have 0 and , so this kind of ruins things for financial calculations. you can use .toFixed of course, but this does not totally eliminate the problems with floating point. it's successive additions and subtractions of small values like 0.01 or smaller and sometimes even values in the range 0.1 that introduce floating point error into calculations.

JavaScript seems to be a subset of Java data type classes. seeing this, there are some Java classes I can see which seem to fit this need: 
http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html
http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html
http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html
http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormatSymbols.html
http://docs.oracle.com/javase/7/docs/api/java/text/spi/DecimalFormatSymbolsProvider.html
http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html
http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Delayed.html


you will have to decide which interfaces on Comparable you do or don't need, or if you need Comparable at all.


BigDecimal is the only class which seems to do decimal. I had to look at dependencies.

if you want to see the problem in action, play around with various values like 0.11, 0.40, 0.41, 0.42 in http://Jesusnjim.com/calculators/finances/cash-change.html
Comment 1 Mathias Bynens 2013-06-07 09:16:33 UTC
This sounds like a feature suggestion for the ECMAScript language, rather than an implementation quirk that should be standardized in http://javascript.spec.whatwg.org/.
Comment 2 Jim Michaels 2013-09-04 07:31:25 UTC
I have no clue how a person would make such a suggestion to ECMA, they have no bug tracking system I know of and no email addresses on their documents.
Comment 3 Michael[tm] Smith 2013-09-04 09:04:44 UTC
(In reply to comment #2)
> I have no clue how a person would make such a suggestion to ECMA, they have
> no bug tracking system I know of and no email addresses on their documents.

https://bugs.ecmascript.org/

I guess you'd probably want to report is against the "Draft for 6th Edition" product, "new feature" component.

https://bugs.ecmascript.org/describecomponents.cgi