1 // © 2018 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
7 #ifndef __SOURCE_NUMBER_MULTIPLIER_H__
8 #define __SOURCE_NUMBER_MULTIPLIER_H__
10 #include "numparse_types.h"
11 #include "number_decimfmtprops.h"
13 U_NAMESPACE_BEGIN
namespace number
{
18 * Wraps a {@link Multiplier} for use in the number formatting pipeline.
20 // Exported as U_I18N_API for tests
21 class U_I18N_API MultiplierFormatHandler
: public MicroPropsGenerator
, public UMemory
{
23 MultiplierFormatHandler() = default; // WARNING: Leaves object in an unusable state; call setAndChain()
25 void setAndChain(const Scale
& multiplier
, const MicroPropsGenerator
* parent
);
27 void processQuantity(DecimalQuantity
& quantity
, MicroProps
& micros
,
28 UErrorCode
& status
) const U_OVERRIDE
;
32 const MicroPropsGenerator
*fParent
;
36 /** Gets a Scale from a DecimalFormatProperties. In Java, defined in RoundingUtils.java */
37 static inline Scale
scaleFromProperties(const DecimalFormatProperties
& properties
) {
38 int32_t magnitudeMultiplier
= properties
.magnitudeMultiplier
+ properties
.multiplierScale
;
39 int32_t arbitraryMultiplier
= properties
.multiplier
;
40 if (magnitudeMultiplier
!= 0 && arbitraryMultiplier
!= 1) {
41 return Scale::byDoubleAndPowerOfTen(arbitraryMultiplier
, magnitudeMultiplier
);
42 } else if (magnitudeMultiplier
!= 0) {
43 return Scale::powerOfTen(magnitudeMultiplier
);
44 } else if (arbitraryMultiplier
!= 1) {
45 return Scale::byDouble(arbitraryMultiplier
);
56 #endif //__SOURCE_NUMBER_MULTIPLIER_H__
57 #endif /* #if !UCONFIG_NO_FORMATTING */