简体   繁体   中英

How to convert non-Latin numerals to their Latin counterparts

I have a system in a different language implemented in Unicode. The condition is that the system must also accept Unicode characters (for digits) and process them accordingly. Is it possible to convert any Unicode characters(that represents numbers) to a sensible English numbers equivalent?

How can I implement that in Javascript?

EDIT: I searched the web and found a chart in unicode.org . There are codes corresponding to the literals i want there. Now, how do i read the code from the input unicode string ?

The Unicode Database contains in column 6-8 information about digit values, decimal digit values and number values (like U+216E: ROMAN NUMERAL FIVE HUNDRED has a number value of 500).

To use this in JavaScript, you might parse that file with some other language and dump the information you need as JSON or similar, and then just look up the value in the JSON from JavaScript.

Documentation of the Unicode Database file format

Either you dump the unicode codepoints into your JSON like this "\€" for U+20AC , then you can just compare the characters, or you can use someString.charCodeAt(somePosition).toString(16) to convert that character to a hex string (like 20ac ) to compare from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM