Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/src/main/scala/java/text/DecimalFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ class DecimalFormat(private[this] val pattern: String, private[this] var symbols

val curr: JavaBigInteger = n.remainder(JavaBigInteger.TEN)
n = n.divide(JavaBigInteger.TEN)
builder.append(curr.intValue)

// Assume non-latin characters 1-9 are at the same offset from the zero digit character
val localizedDigit = (symbols.getZeroDigit - DecimalFormatUtil.PatternCharZeroDigit) + curr.intValue
builder.append(localizedDigit)
digitsWritten += 1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,30 @@ class NumberFormatTest extends LocaleTestSetup {
assertEquals("\u22122,147,483,648", nf.format(Int.MinValue))
assertEquals("\u22129,223,372,036,854,775,808", nf.format(Long.MinValue))
}

// This works with JAVA_OPTS="-Djava.locale.providers=CLDR"
@Test def test_non_latin(): Unit = {
// Arabic-Indic
if (!Platform.executingInJVM) {
LocaleRegistry.installLocale(ar_JO)
}

val locale = Locale.forLanguageTag("ar-JO")
assertTrue(locale != null)
Locale.setDefault(locale) // Override the US default

val df = NumberFormat.getInstance(locale)
assertEquals("Decimal Format", "١٬٢٣٤٬٥٦٧٬٨٩٠٫١٢٣", df.format(1234567890.123))

val pf = NumberFormat.getPercentInstance(locale)
assertEquals("Percent Format", "١٢٣٬٤٥٦٬٧٨٩٬٠٠٠٪", pf.format(1234567890))

val nf = NumberFormat.getNumberInstance(locale)
println(s"number: ${nf.format(1234567890)}")
assertEquals("Number Format", "١٬٢٣٤٬٥٦٧٬٨٩٠", nf.format(1234567890))

val cf = NumberFormat.getCurrencyInstance(locale)
println(s"currencyFormat: ${cf.format(123456789.01)}")
assertEquals("Currency Format", "د.أ.‏ ١٢٣٬٤٥٦٬٧٨٩٫٠١٠", cf.format(123456789.01))
}
}