swift-foundation icon indicating copy to clipboard operation
swift-foundation copied to clipboard

`Decimal.FormatStyle` does not always respect the locale's decimalSeparator

Open StevenSorial opened this issue 3 years ago • 14 comments

Description Decimal.FormatStyle does not always respect the locale's decimalSeparator, also, the same error occurs with FloatingPointFormatStyle

Steps to reproduce 1- Set the iPhone region to Germany. 2- Set the iPhone language to English (US). 3- Set the Number Format decimal separator to period instead of the default comma.

Expected behavior

    let number: Decimal = 1.5

    let newFormatter = Decimal.FormatStyle.number
    let newResult = number.formatted(newFormatter) // 1,5 ❌

    let oldFormatter = NumberFormatter()
    oldFormatter.numberStyle = .decimal

    let oldResult = oldFormatter.string(from: number as NSNumber)! // 1.5 ✅

IMG_2957 Medium

Environment

  • Swift version: 5.7
  • Xcode version: 14.2
  • Deployment target: iOS 16.3

StevenSorial avatar Feb 26 '23 16:02 StevenSorial

feedback: FB11980066

StevenSorial avatar Feb 26 '23 16:02 StevenSorial

cc @parkera

AnthonyLatsis avatar Feb 27 '23 03:02 AnthonyLatsis

@hamishknight Sorry to bother you with this. Could you transfer this too?

AnthonyLatsis avatar May 17 '23 20:05 AnthonyLatsis

Sure

hamishknight avatar May 17 '23 20:05 hamishknight

We're blocked by ICU to be able to support this unfortunately

itingliu avatar May 18 '23 00:05 itingliu

Apologies for my ignorance, how that is the case if NumberFormatter is able to format it correctly?

StevenSorial avatar May 18 '23 08:05 StevenSorial

Apologies for my ignorance, how that is the case if NumberFormatter is able to format it correctly?

NumberFormatter uses a legacy ICU API, where we've moved onto a modern one for Decimal.FormatStyle

itingliu avatar May 18 '23 23:05 itingliu

Hiya, is there any progress on this? I feel like this is a pretty bug bug because we cannot format decimals into the users preferred format and worse still we cannot parse from a user typed string into a decimal?

justingiffard-impact avatar Jun 14 '24 08:06 justingiffard-impact