Closed
Bug 225237
Opened 22 years ago
Closed 22 years ago
Setting value of text field with maxlength defined, doesn't consider scientific number notation (e)
Categories
(Core :: Layout: Form Controls, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: mbabuskov, Unassigned)
References
()
Details
User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624
Build Identifier: http://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.5/mozilla-win32-1.5-installer.exe
Example:
If I have text input field, with maxlength set to 10. Doing something like this,
gives incorrect values:
testfield.value = 12/25021930000;
if the field hasn't got maxlength I get correct value:
4.795793130266131e-10
if the field has maxlenght set to ex. 10, I get:
4.79579313
Which is wrong, since the number is most closer to zero, a is far away from 4.79
Reproducible: Always
Steps to Reproduce:
1. create a text input field with maxlength set to 10
2. assign: field.value = 12/250219300
Actual Results:
The result is 4.79579313
Expected Results:
It should print zero instead.
Tested on Mozilla 1.4, 1.5 and Mozilla Firebird 0.6 and 0.7
I haven't been able to find any good workarounds. Checking if (number <
0.000something) all over the places is not a good idea, especially since I have
pretty large web application running via Mozilla.
Comment 1•22 years ago
|
||
|maxlength| is not a property of JavaScript Engine.
Not sure of the correct component, however.
Reassigning to Form Controls for further triage-
Assignee: general → form
Status: UNCONFIRMED → NEW
Component: JavaScript Engine → Layout: Form Controls
Ever confirmed: true
QA Contact: PhilSchwartau → ian
The input field recieves just a string and doesn't know it was a number in its
previous life. If you want to limit precision, use toPrecision(),
toExponential() or toFixed(). And this is surely no blocker.
Comment 3•22 years ago
|
||
The number "4.795793130266131e-10" is cast to a DOMString as soon as you try to
put it into testfield.value. Since the string is limited to 10 characters by
maxfield, it's cut back accordingly.
Don't try to do math with string data types; see the advice in comment #2. INVALID.
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → INVALID
| Reporter | ||
Comment 4•22 years ago
|
||
.toPrecision still uses e notation, so it isn't good, but toFixed works. Thanx.
I marked it "blocker" since we have web application that uses the approach I
wrote about, and other (older) browsers don't support toPrecision() and
toFixed(), so we couldn't change the application since it wouldn't work.
However, I still think it's wrong of Mozilla engine to convert value of
0.000000000479579313 as string "4.79579313"
BTW, do you know where can I read Mozilla JavaScript reference, or something
like that, so I can see whether toPrecision() and similar functions are
supported by Mozilla?
You need to log in
before you can comment on or make changes to this bug.
Description
•