Data.Currency
- Package
- purescript-currency
- Repository
- philippedev101/purescript-currency
#Money Source
#mkMoney Source
mkMoney :: forall c. CurrencyScale c => Int -> Int -> Money cConstruct a Money value from major + minor units using the currency's
known scale. e.g. mkMoney 10 50 :: Money "EUR" for EUR 10.50.
#fromNumber Source
fromNumber :: forall c. Int -> Number -> Maybe (Money c)Convert from a Number (representing major units, e.g. 10.50) by multiplying by minorPerMajor and truncating. Returns Nothing if the Number is not finite.
#isPositive Source
isPositive :: forall c. Money c -> BooleanCheck if an amount is strictly positive.
#isNegative Source
isNegative :: forall c. Money c -> BooleanCheck if an amount is strictly negative.
#divide Source
divide :: forall c. RoundingMode -> Money c -> Int -> Money cDivide a money amount by an integer with a rounding mode.
Unlike allocate, this does not preserve the total — rounding may
cause a small discrepancy. Use allocate or split when the total
must be preserved exactly.
#allocate Source
allocate :: forall c. Money c -> Array Int -> Array (Money c)Distribute a Money amount according to a list of ratios. The remainder (due to integer division) is distributed one unit at a time across the parts, starting from the first. The output array has the same length as the ratios array. All ratios must be non-negative; the total of ratios must be positive.
#haveSameAmount Source
haveSameAmount :: forall c1 c2. Money c1 -> Money c2 -> BooleanCompare amounts across different currencies (ignoring currency). Returns true if the underlying minor unit counts are equal.
#hasSubUnits Source
hasSubUnits :: forall c. Int -> Money c -> BooleanCheck if the amount has fractional minor units at the given scale.
e.g. hasSubUnits 100 (fromCents 1050) is true (10.50 has sub-units),
hasSubUnits 100 (fromCents 1000) is false (10.00 has none).
#toDecimal Source
toDecimal :: forall c. CurrencyScale c => Money c -> StringFormat a Money amount as a decimal string, using the currency's
known scale to determine the number of decimal places.
e.g. for EUR (scale 100): toDecimal (fromCents 1050) = "10.50"
e.g. for JPY (scale 1): toDecimal (fromCents 500) = "500"
#convert Source
convert :: forall from to. RoundingMode -> Money from -> Int -> Int -> Money toConvert a Money amount from one currency to another using an exchange
rate expressed as numerator/denominator to avoid floating point.
e.g. EUR to USD at rate 1.0835: convert RoundHalfEven m 10835 10000
The caller is responsible for adjusting for different minor unit scales
between source and target currencies.
#CurrencyScale Source
class CurrencyScale :: Symbol -> Constraintclass CurrencyScale c where
Type class for currencies with a known minor-unit scale. The scale is the number of minor units per major unit (e.g. 100 for EUR/USD, 1 for JPY, 1000 for BHD).
Members
Instances
CurrencyScale "EUR"CurrencyScale "USD"CurrencyScale "GBP"CurrencyScale "CHF"CurrencyScale "JPY"CurrencyScale "BHD"CurrencyScale "KWD"
Re-exports from Data.Currency.Rounding
#RoundingMode Source
data RoundingModeRounding modes for operations that may produce fractional minor units.
Constructors
Instances
- Modules
- Data.
Currency - Data.
Currency. Rounding