Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F5239
js_numeric_test.js
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Authored By
•
bzimport
Nov 21 2014, 10:23 PM
2014-11-21 22:23:38 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
js_numeric_test.js
View Options
This document is not UTF8. It was detected as Shift JIS and converted to UTF8 for display.
var
regexp
=
/^[+-]?(?:\d{1,3}(?:\,\d{3})*)*\.?\d*(?:[eE][+-]?\d+(?:\,\d{3})*|[\u00bc\u00bd\u00be])?[%\u00b0]?$/
var
strings
=
[
'-0.5e-55'
,
//0 should be true
'-.5e-55'
,
//1 should be true
'.5e-55'
,
//2 should be true
'5e-55'
,
//3 should be true
'5,000e-55'
,
//4 should be true
'5,000e-5,500'
,
//5 should be true
'5,000e-5,50'
,
//6 should be false
'e-55'
,
//7 should be false
'-0.5e55'
,
//8 should be true
'-0.5e-5.5'
,
//9 should be false
'-0.5e55シ'
,
//10 should be false
'-0.5e55%'
,
//11 should be true
'-5シ'
,
//12 should be true
'-5.5シ'
//13 should be detected as true despite being wrong
]
function
ts_parseFloat
(
num
)
{
if
(
!
num
)
return
0
;
var
div
=
/%$/
.
test
(
num
)
?
100
:
1
;
num
=
parseFloat
(
num
.
replace
(
/\u00bc/g
,
'.25'
).
replace
(
/\u00bd/g
,
'.5'
).
replace
(
/\u00be/g
,
'.75'
).
replace
(
/\u00b0/g
,
''
).
replace
(
/%/g
,
''
).
replace
(
/,/g
,
''
));
return
(
isNaN
(
num
)
?
0
:
(
num
/
div
));
}
function
testnum
(
string
)
{
// if (regexp.test(string) && !/^[eE]/.test(string))
// WScript.echo(i + '\t' + ts_parseFloat(string));
// else
// WScript.echo(i + '\t' + false);
WScript
.
echo
(
i
+
'\t'
+
(
regexp
.
test
(
string
)
&&
!
/^[eE]/
.
test
(
string
)));
}
for
(
var
i
=
0
;
i
<
strings
.
length
;
i
++
)
{
testnum
(
strings
[
i
])
}
//testnum('56,000')
//WScript.echo(parseFloat('e2'));
File Metadata
Details
Attached
Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4800
Default Alt Text
js_numeric_test.js (1 KB)
Attached To
Mode
T17422: Wikibits patch #10 - more numbers
Attached
Detach File
Event Timeline
Log In to Comment