summaryrefslogtreecommitdiffstats
path: root/src/number.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/number.js')
-rw-r--r--src/number.js17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/number.js b/src/number.js
index 0ca8831..8eb7a1c 100644
--- a/src/number.js
+++ b/src/number.js
@@ -12,20 +12,20 @@ SVG.Number = SVG.invent({
this.value = isNaN(value) ? 0 : !isFinite(value) ? (value < 0 ? -3.4e+38 : +3.4e+38) : value
} else if (typeof value === 'string') {
- unit = value.match(SVG.regex.unit)
+ unit = value.match(SVG.regex.numberAndUnit)
if (unit) {
// make value numeric
this.value = parseFloat(unit[1])
-
+
// normalize
- if (unit[2] == '%')
+ if (unit[5] == '%')
this.value /= 100
- else if (unit[2] == 's')
+ else if (unit[5] == 's')
this.value *= 1000
-
+
// store unit
- this.unit = unit[2]
+ this.unit = unit[5]
}
} else {
@@ -48,6 +48,9 @@ SVG.Number = SVG.invent({
this.value
) + this.unit
}
+ , toJSON: function() {
+ return this.toString()
+ }
, // Convert to primitive
valueOf: function() {
return this.value
@@ -71,7 +74,7 @@ SVG.Number = SVG.invent({
// Convert to different unit
, to: function(unit) {
var number = new SVG.Number(this)
-
+
if (typeof unit === 'string')
number.unit = unit