JScience uses Unicode characters in the String representations of some of its Units.  For example, Unicode U+2103 (℃) is used to represent the unit for degrees Celsius.  Those characters can cause problems with fonts and/or platforms (Windows, typically) which do not contain or recognize them.  Instead, you may see a question mark, box, or other unfamiliar glyph.  Here is the symbol for degrees Celsius again — ℃ — can you see it properly?

Using UnitFormat.label(), we can override the String representation to something more compatible, useful, or just different.  Here’s how I changed degrees Celsius to be more compatible with my co-workers Windows systems.

UnitFormat.getInstance().label(SI.CELSIUS, "\u00B0" + "C");

And here’s how I changed knots to be represented by kts instead of the default, kn.

UnitFormat.getInstance().label(NonSI.KNOT, "kts");

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

   
© 2011 And now here's something… Suffusion theme by Sayontan Sinha