Actually you can just say (0).toFixed(2);
Primitives get temporarily coerced to their object wrappers when faced with attribute or function calls. I've never yet had to use new Number() but there may yet be a scenario On Feb 4, 7:51 am, jemptymethod <[email protected]> wrote: > I'm setting ExtJS form values in one of their ubiquitous config > objects based on JSON data from an Ajax call. > > For currency fields I am calling "toFixed(2)" on the numbers such as: > > jsonObj.shippingAndHandling.toFixed(2) > jsonObj.totalDueToday.toFixed(2) > > Etcetera0 > > But I have a requirement to default a particular field to 0.00 and > when I specify 0.00 as the value in the config object, it shows up as > 0 in the UI > > As a work around instead of trying to specify 0.00 I can pass the > following and it successfully renders 0.00 in the UI > > (new Number(0)).toFixed(2) > > Am wondering what the "mentors" (and anybody else who wants to weigh > in ;) think of this as possibly being a useful use case for using one > Javascript's primitive object wrappers. By the way, specifying the > string '0.00' in the config would surely work if the form field was an > Ext.form.TextField but possibly not if an Ext.form.NumberField? -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
