1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
6 #if !UCONFIG_NO_FORMATTING
8 #include "unicode/numberformatter.h"
9 #include "number_types.h"
12 using namespace icu::number
;
13 using namespace icu::number::impl
;
16 ScientificNotation
Notation::scientific() {
17 // NOTE: ISO C++ does not allow C99 designated initializers.
18 ScientificSettings settings
;
19 settings
.fEngineeringInterval
= 1;
20 settings
.fRequireMinInt
= false;
21 settings
.fMinExponentDigits
= 1;
22 settings
.fExponentSignDisplay
= UNUM_SIGN_AUTO
;
24 union_
.scientific
= settings
;
25 return {NTN_SCIENTIFIC
, union_
};
28 ScientificNotation
Notation::engineering() {
29 ScientificSettings settings
;
30 settings
.fEngineeringInterval
= 3;
31 settings
.fRequireMinInt
= false;
32 settings
.fMinExponentDigits
= 1;
33 settings
.fExponentSignDisplay
= UNUM_SIGN_AUTO
;
35 union_
.scientific
= settings
;
36 return {NTN_SCIENTIFIC
, union_
};
39 ScientificNotation::ScientificNotation(int8_t fEngineeringInterval
, bool fRequireMinInt
,
40 impl::digits_t fMinExponentDigits
,
41 UNumberSignDisplay fExponentSignDisplay
) {
42 ScientificSettings settings
;
43 settings
.fEngineeringInterval
= fEngineeringInterval
;
44 settings
.fRequireMinInt
= fRequireMinInt
;
45 settings
.fMinExponentDigits
= fMinExponentDigits
;
46 settings
.fExponentSignDisplay
= fExponentSignDisplay
;
48 union_
.scientific
= settings
;
49 *this = {NTN_SCIENTIFIC
, union_
};
52 Notation
Notation::compactShort() {
54 union_
.compactStyle
= CompactStyle::UNUM_SHORT
;
55 return {NTN_COMPACT
, union_
};
58 Notation
Notation::compactLong() {
60 union_
.compactStyle
= CompactStyle::UNUM_LONG
;
61 return {NTN_COMPACT
, union_
};
64 Notation
Notation::simple() {
69 ScientificNotation::withMinExponentDigits(int32_t minExponentDigits
) const {
70 if (minExponentDigits
>= 1 && minExponentDigits
<= kMaxIntFracSig
) {
71 ScientificSettings settings
= fUnion
.scientific
;
72 settings
.fMinExponentDigits
= static_cast<digits_t
>(minExponentDigits
);
73 NotationUnion union_
= {settings
};
74 return {NTN_SCIENTIFIC
, union_
};
76 return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR
};
81 ScientificNotation::withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay
) const {
82 ScientificSettings settings
= fUnion
.scientific
;
83 settings
.fExponentSignDisplay
= exponentSignDisplay
;
84 NotationUnion union_
= {settings
};
85 return {NTN_SCIENTIFIC
, union_
};
88 #endif /* #if !UCONFIG_NO_FORMATTING */