Skip to content

Instantly share code, notes, and snippets.

@sanmai
Last active January 19, 2018 06:57
Show Gist options
  • Save sanmai/852f954ec5aa9bd787a371aaad9ea598 to your computer and use it in GitHub Desktop.
Save sanmai/852f954ec5aa9bd787a371aaad9ea598 to your computer and use it in GitHub Desktop.
Convert full-width digits to half-width (ASCII) digits. 入力値を半角に変換して返却する
function toHankaku(original) {
var result = '';
for (var i = 0; i < original.length; i = i+1) {
var tmp = original.charCodeAt(i);
if ((0xff0f < tmp) && (tmp < 0xff1a)) {
result += String.fromCharCode(tmp - 0xfee0);
} else {
result += String.fromCharCode(tmp);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment