tnj / localized-digits

Android app demonstrates how `String.format("%d", 0)` are localized on locales

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

localized-digits

Circle CI Try it on your device via DeployGate

TL;DR

You must use String.format(Locale.US, "%d", 1) to produce machine-readable expression of digits in string, otherwise it may produce non-ascii localized characters in some locales.

What is this?

This single activity application shows the result of String.format("%d", 1234567890) in available locales on your device.

device-2015-07-31-024722

That's all, but you can try it on your device if you want.

Background

Sometimes you face to unexpected behavior on popular standard functions.

String result = String.format("%d", 1);

Most people expects result is 1, but in some cases this is not true. The result depends on current locale you use.

This is expected, documented behavior of java.util.Formatter. Each digit expression is generated as offset from zero-digit character on current locale (for example 0 in en, ٠ in ar, and in my) by using java.text.DecimalFormatSymbols#getZeroDigit().

About

Android app demonstrates how `String.format("%d", 0)` are localized on locales


Languages

Language:Java 100.0%