- From: Nils Dagsson Moskopp <nils@dieweltistgarnichtso.net>
- Date: Thu, 08 Jan 2015 03:45:04 +0100
- To: Michael Gratton <mike@vee.net>, whatwg@lists.whatwg.org
Michael Gratton <mike@vee.net> writes: > Hi, > > As the spec currently stands, use of <input type=number> is unsuitable > for currency and other input that require a minimum number of decimal > points displayed. When displaying decimal currency values, the typical > convention is that a precision of two decimal points is used, > regardless of numeric value. That is, one dollar is displayed as > "1.00", not "1". However the latter is the result when using <input > type=number> in implementations that follow the spec, such as Chrome > and Firefox. > > Section "4.10.5.1.9 Number state (type=number)" currently states: "If > the user agent provides a user interface for selecting a number, then > the value must be set to the best representation of the number > representing the user's selection as a floating-point number" - > effectively by calling JavaScript's ToString on the number. This gives > rise to the undesirable representation above. > > Since both the spec and existing implementations use the step attribute > to effectively specify the maximum number of decimal points for the > representation of the number, it also seems reasonable for the step > attribute to also define the minimum. This can perhaps be acheived by > changing the definition of the "best representation of the number n as > a floating-point number" to use the JavaScript Number.ToPrecision > function, and obtaining the precision from the step attribute, rather > than using ToString. > > This will work for integral currencies by specifying a step of 1, as > well as decimal currencies that that use a single decimal point, by > specifying a step of "0.1". > > Thoughts? I think that float is simply the wrong data type for fractional amounts of currency. Let me tell you an abrasive programmer joke regarding that: bool gender; int phone_number; float money_amount; Cheers, -- Nils Dagsson Moskopp // erlehmann <http://dieweltistgarnichtso.net>
Received on Thursday, 8 January 2015 02:45:41 UTC