moov-io / rtp20022

ISO20022 messages in Go for Real Time Payments (RTP)
Apache License 2.0
40 stars 9 forks source link

rtp.Amount trim trailing zero (or not force the decimal part) #49

Open jerome-laforge opened 8 months ago

jerome-laforge commented 8 months ago

Hello, Is it possible to not force the decimal part of rtp.Amount? Because some currencies:

adamdecaf commented 8 months ago

This repository is used for RTP (by The Clearing House) which only allows USD. They don't support all of the currencies that ISO 20022 does.

Edit: See https://github.com/moov-io/rtp20022/issues/47#issuecomment-1834005157 for more details on how to support these differences.

jerome-laforge commented 8 months ago

make sens, but is it possible to define global variable for precision of amount (as for ISODate https://github.com/jerome-laforge/rtp20022/commit/ac6fa8700c64570bc8c2e0866f2fc66affd78e50) with default value set to 2 (current behavior for USD) ?

    f := 1.5
    fmt.Println(strconv.FormatFloat(f, 'f', -1, 64)) // 1.5 no trailling zeros
    fmt.Println(strconv.FormatFloat(f, 'f', 2, 64))  // 1.50 
    fmt.Println(strconv.FormatFloat(f, 'f', 3, 64))  // 1.500

https://go.dev/play/p/wQUjk5C34-5