summaryrefslogtreecommitdiff
path: root/design-documents/051-fractional-digits.rst
blob: 21930d1b0960728c048f71a3791fa4e61190ebf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
DD 51: Fractional Digits
#########################

Summary
=======

This design document specifies how an amount's fractional digits should be rendered.

Motivation
==========

Since different currencies have different ways to show/render fractionals, the end-user apps should follow these guidelines.

Requirements
============

There is already a specification for ScopedCurrencyInfo - this needs to change

We need three characteristics for fractional digits for each currency:

a) the number of fractional digits [0..8] the user may enter in a TextInputField

b) the number of fractional digits [0..8] to be rendered as normal characters (same font and size as the integer digits).
   All additional fractional digits will be rendered as SuperScriptDigits as known from gas filling stations.
   The UI should never round or truncate any amount, but always render all existing digits (except trailing zeroes, see c).

c) the number of fractional digits [0..8] to be rendered as trailing zeroes (including SuperScript digits).
   E.g. if this is 2 (and normal == 2), then render $5 as “$ 5.00”.
   If this is 3 (and normal == 2), then render $5 as “$ 5.00⁰” with two normal trailing zeroes and one superscript trailing zero.

Usually, all these three numbers have the same value, which means that in case of e.g. “2” (used for €,$,£) the user can enter
cent/penny values (but not a fraction of those), these cents/pennies are always shown (even if they are 0) as two normal digits
after the decimal separator, and fractions of a cent/penny are rendered as SuperScriptDigits, but only if they are not trailing zeroes.

iOS has a built-in currency formatter, which knows how to deal with thousands-separators and where to apply them
(e.g. India uses a mixture of hundreds and thousands instead of putting the separator after each 3 digits like western currencies).
However, this formatter will round after two (or three) fractional digits and thus cannot be used for the whole amount.

(please add information about Android and WebEx here)


Proposed Solution
=================

  .. code-block:: swift

      public struct ScopedCurrencyInfo: Codable, Sendable {
          let decimalSeparator: String                // e.g. “.” for $ and ¥; “,” for €
          let numFractionalInputDigits: Int           // how much digits the user may enter after the decimalSeparator
          let numFractionalNormalDigits: Int          // €,$,£: 2; some arabic currencies: 3, ¥: 0
          let numFractionalTrailingZeroDigits: Int    // usually same as numFractionalNormalDigits, but e.g. might be 2 for ¥
          let isCurrencyNameLeading: Bool             // true for “$ 3.50”; false for “3,50 €”
      }

For iOS, we plan to format the integer part of the amount with the built-in currency formatter, then add the fractional part
according to this document.

(please add information about Android and WebEx here)



Definition of Done
==================

(Only applicable to design documents that describe a new feature.  While the
DoD is not satisfied yet, a user-facing feature **must** be behind a feature
flag or dev-mode flag.)

Alternatives
============

Drawbacks
=========

Discussion / Q&A
================

(This should be filled in with results from discussions on mailing lists / personal communication.)