Last active
April 28, 2017 11:38
-
-
Save romanmikhailov/83dfd26b4b822adc3d6fe93ee7e74ac0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Numbers example.</title> | |
<style type="text/css"> | |
body { | |
width: 100%; | |
height: 100%; | |
} | |
.app-container { | |
width: 100%; | |
height: 100%; | |
} | |
.number-input, .number-output { | |
width: 300px; | |
height: 25px; | |
line-height: 25px; | |
margin-bottom: 10px; | |
font-family: "微軟正黑體", "Microsoft JhengHei", Tahoma , Verdana , Arial , sans-serif; | |
} | |
.label { | |
width: 70px; | |
display: inline-block; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="app-container"> | |
<span class="label">Number: </span><input id="numberInput" type="text" class="number-input"/> | |
<br/> | |
<span class="label">Result: </span><span id="numberOutput" class="number-output"> </span> | |
</div> | |
<script type="text/javascript"> | |
(function (console) { "use strict"; | |
Math.__name__ = true; | |
var NumberPresenter = function() { }; | |
NumberPresenter.__name__ = true; | |
NumberPresenter.numberToShortStringChinese = function(value) { | |
var newValue; | |
var sign; | |
if(value >= 1000000000000) { | |
newValue = value / 1000000000000; | |
sign = "兆"; | |
} else if(value >= 100000000) { | |
newValue = value / 100000000; | |
sign = "亿"; | |
} else if(value >= 10000) { | |
newValue = value / 10000; | |
sign = "万"; | |
} else { | |
newValue = value; | |
sign = ""; | |
} | |
console.log(sign); | |
return "" + NumberPresenter.floatToIntString(newValue) + sign; | |
}; | |
NumberPresenter.floatToIntString = function(amount) { | |
console.log(amount); | |
var stringAmount; | |
if(amount < 0) stringAmount = "-"; else stringAmount = ""; | |
amount = Math.abs(amount); | |
stringAmount += Std.string(Math.floor(amount)); | |
var decimalMultiplier; | |
var decimalDigitsAmount; | |
if(amount < 10) decimalDigitsAmount = 3; else if(amount < 100) decimalDigitsAmount = 2; else if(amount < 1000) decimalDigitsAmount = 1; else decimalDigitsAmount = 0; | |
decimalMultiplier = Math.pow(10,decimalDigitsAmount); | |
var decimalPart = Math.floor(amount * decimalMultiplier) % decimalMultiplier; | |
if(decimalPart != 0) { | |
var decimalPartString; | |
if(decimalPart == null) decimalPartString = "null"; else decimalPartString = "" + decimalPart; | |
while(decimalPartString.length < decimalDigitsAmount) decimalPartString = "0" + decimalPartString; | |
while(decimalPartString.length != 0 && decimalPartString.charAt(decimalPartString.length - 1) == "0") decimalPartString = decimalPartString.substring(0,decimalPartString.length - 1); | |
stringAmount += "." + decimalPartString; | |
} | |
return stringAmount; | |
}; | |
var NumbersAppClient = function() { }; | |
NumbersAppClient.__name__ = true; | |
NumbersAppClient.main = function() { | |
var input = window.document.getElementById("numberInput"); | |
var output = window.document.getElementById("numberOutput"); | |
input.addEventListener("input",function() { | |
var result = " "; | |
if(input.value != null && input.value != "") { | |
var resultFloat = +input.value.split(",").join(""); | |
result = NumberPresenter.numberToShortStringChinese(resultFloat); | |
} | |
output.innerHTML = result; | |
}); | |
input.focus(); | |
}; | |
var Std = function() { }; | |
Std.__name__ = true; | |
Std.string = function(s) { | |
return js_Boot.__string_rec(s,""); | |
}; | |
var js_Boot = function() { }; | |
js_Boot.__name__ = true; | |
js_Boot.__string_rec = function(o,s) { | |
if(o == null) return "null"; | |
if(s.length >= 5) return "<...>"; | |
var t = typeof(o); | |
if(t == "function" && (o.__name__ || o.__ename__)) t = "object"; | |
switch(t) { | |
case "object": | |
if(o instanceof Array) { | |
if(o.__enum__) { | |
if(o.length == 2) return o[0]; | |
var str2 = o[0] + "("; | |
s += "\t"; | |
var _g1 = 2; | |
var _g = o.length; | |
while(_g1 < _g) { | |
var i1 = _g1++; | |
if(i1 != 2) str2 += "," + js_Boot.__string_rec(o[i1],s); else str2 += js_Boot.__string_rec(o[i1],s); | |
} | |
return str2 + ")"; | |
} | |
var l = o.length; | |
var i; | |
var str1 = "["; | |
s += "\t"; | |
var _g2 = 0; | |
while(_g2 < l) { | |
var i2 = _g2++; | |
str1 += (i2 > 0?",":"") + js_Boot.__string_rec(o[i2],s); | |
} | |
str1 += "]"; | |
return str1; | |
} | |
var tostr; | |
try { | |
tostr = o.toString; | |
} catch( e ) { | |
return "???"; | |
} | |
if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") { | |
var s2 = o.toString(); | |
if(s2 != "[object Object]") return s2; | |
} | |
var k = null; | |
var str = "{\n"; | |
s += "\t"; | |
var hasp = o.hasOwnProperty != null; | |
for( var k in o ) { | |
if(hasp && !o.hasOwnProperty(k)) { | |
continue; | |
} | |
if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") { | |
continue; | |
} | |
if(str.length != 2) str += ", \n"; | |
str += s + k + " : " + js_Boot.__string_rec(o[k],s); | |
} | |
s = s.substring(1); | |
str += "\n" + s + "}"; | |
return str; | |
case "function": | |
return "<function>"; | |
case "string": | |
return o; | |
default: | |
return String(o); | |
} | |
}; | |
String.__name__ = true; | |
Array.__name__ = true; | |
NumbersAppClient.main(); | |
})(typeof console != "undefined" ? console : {log:function(){}}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment