1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > html强制转换为数字 在html页面中将英文数字转换为阿拉伯数字

html强制转换为数字 在html页面中将英文数字转换为阿拉伯数字

时间:2024-02-26 12:33:07

相关推荐

html强制转换为数字 在html页面中将英文数字转换为阿拉伯数字

P9Q..

5

将英语(拉丁)数字转换为波斯数字和阿拉伯数字。

//English to Persian digits.

String.prototype.toFa= function() {

return this.replace(/\d/g, d => '??????????'[d])

}

//English to Arabic digits.

String.prototype.toAr= function() {

return this.replace(/\d/g, d => '??????????'[d])

}

//English to either Persian or Arabic digits.

String.prototype.toIn= function(e) {

return this.replace(/\d/g, d => e ? '??????????'[d] : '??????????'[d])

}

//English to Persian digits using unicode.

String.prototype.toFaUni= function() {

return this.replace(/\d/g, d => String.fromCharCode('0x06F'+d))

}

//English to Arabic digits using unicode.

String.prototype.toArUni= function() {

return this.replace(/\d/g, d => String.fromCharCode('0x066'+d))

}

//English to either Persian or Arabic digits.

String.prototype.toInUni= function(e) {

return this.replace(/\d/g, d => String.fromCharCode('0x06'+(e ? '6':'F')+d))

}

//examples

let text = 'It is 30/08/ at 8:24 AM'

//using array

alert(text.toFa())

alert(text.toAr())

alert(text.toIn(0))

alert(text.toIn(1))

//using unicode

alert(text.toFaUni())

alert(text.toArUni())

alert(text.toInUni(0))

alert(text.toInUni(1))

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。