While dealing with unicode encoded characters in Java, I used Normalizer to normalize it and convert it to a String. Below is the code I used:
input = "¼";
input = Normalizer.normalize(input,Normalizer.Form.NFKD);
output: 1⁄4.
The forward slash that the method used was "⁄"
whose unicode encoding is \u2044
as opposed to the regular forward slash that I am able to type using my keyboard which is "/"
encoded as \u002f
.
What is the difference between these and when should one be used over another?
Thanks in advance.
Rishit
Unicode these days contains heaps of variations of the common non-letter characters, and slashes are no exception. (That's not even all of them - search for "solidus" to get some more.) You've got fraction slashes (your one), full-width slashes, division slashes (yup, that's separate from the fraction one), thick slashes, extra-thick slashes - the list goes on.
The good news is you get to decide what slash is appropriate for your context.
If you're wanting to normalise just because you don't want fractions to appear squashed into a single character, or you want all fractions to display identically (unicode obviously can't have a character for every possible fraction) then using this fraction slash is probably what you want to go with.
On the other hand, if you want to normalise because you want to reduce the set of available characters to those that can be easily typed on a standard keyboard, it's likely the standard forward slash you should go with.