android - NumberFormat bracketted text to negative numbers -
im displaying negative amount in activity using
double value = -1.0; numberformat defaultformat = numberformat.getcurrencyinstance(locale.us); string formattedtext = defaultformat.format(value);
but when run on samsung galaxy s5 (android 4.4.2)
i'm getting ($1.0)
nexus 5 (android 5.1.1)
gives -$1.0
.
what issue here ?
be wary of default locale
note there many convenience methods automatically use default locale, using them may lead subtle bugs.
the default locale appropriate tasks involve presenting data user. in case, want use user's date/time formats, number formats, rules conversion lowercase, , on. in case, it's safe use convenience methods.
the default locale not appropriate machine-readable output. best choice there locale.us – locale guaranteed available on devices, , fact has no surprising special cases , used (especially computer-computer communication) means tends efficient choice too.
a common mistake implicitly use default locale when producing output meant machine-readable. tends work on developer's test devices (especially because many developers use en_us), fails when run on device user in more complex locale.
for example, if you're formatting integers locales use non-ascii decimal digits. example, if you're formatting floating-point numbers locales use ',' decimal point , '.' digit grouping. that's correct human-readable output, cause problems if presented computer (parsedouble(string) can't parse such number, example). should wary of tolowercase() , touppercase() overloads don't take locale: in turkey, example, characters 'i' , 'i' won't converted 'i' , 'i'. correct behavior turkish text (such user input), inappropriate for, say, http headers.
Comments
Post a Comment