On Fri, Feb 4, 2011 at 4:51 PM, 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)
>
> Etcetera
>
> 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
>

Do you specify it as the number literal 0.00 or the string "0.00". It's
probably the latter you will want.


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

Yes, that creates the string "0.00". You can just use the string directly.


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


No. Nope. Not. Never.
There is no useful case for using them.
And in this case it's completely unnecessary, you would get the same result
from
 (0).toFixed(2)
or,slightly less readable: 0..toFixed(2)


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


It is what you are doing, so it seems it works. You are just doing it in a
roundabout way.
Remember, Number.prototype.toFixed returns a string, not a number.

/L

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

Reply via email to