|
@ -272,7 +272,7 @@ var web3 = { |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
toEth: function(str) { |
|
|
toEth: function(str) { |
|
|
var val = typeof str === "string" ? str.indexOf('0x') == 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str; |
|
|
var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str; |
|
|
var unit = 0; |
|
|
var unit = 0; |
|
|
var units = [ 'wei', 'Kwei', 'Mwei', 'Gwei', 'szabo', 'finney', 'ether', 'grand', 'Mether', 'Gether', 'Tether', 'Pether', 'Eether', 'Zether', 'Yether', 'Nether', 'Dether', 'Vether', 'Uether' ]; |
|
|
var units = [ 'wei', 'Kwei', 'Mwei', 'Gwei', 'szabo', 'finney', 'ether', 'grand', 'Mether', 'Gether', 'Tether', 'Pether', 'Eether', 'Zether', 'Yether', 'Nether', 'Dether', 'Vether', 'Uether' ]; |
|
|
while (val > 3000 && unit < units.length - 1) |
|
|
while (val > 3000 && unit < units.length - 1) |
|
@ -281,10 +281,14 @@ var web3 = { |
|
|
unit++; |
|
|
unit++; |
|
|
} |
|
|
} |
|
|
var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2); |
|
|
var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2); |
|
|
|
|
|
var replaceFunction = function($0, $1, $2) { |
|
|
|
|
|
return $1 + ',' + $2; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
while (true) { |
|
|
while (true) { |
|
|
var o = s; |
|
|
var o = s; |
|
|
s = s.replace(/(\d)(\d\d\d[\.\,])/, function($0, $1, $2) { return $1 + ',' + $2; }); |
|
|
s = s.replace(/(\d)(\d\d\d[\.\,])/, replaceFunction); |
|
|
if (o == s) |
|
|
if (o === s) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
return s + ' ' + units[unit]; |
|
|
return s + ' ' + units[unit]; |
|
|