Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#52813 update(money-math): missing methods by
Browse files Browse the repository at this point in the history
@peterblazejewicz

- integralPart
- amountToCents
- centsToAmount
- tests amended

https://github.com/ikr/money-math/blob/master/spec/money.spec.js

Thanks!
  • Loading branch information
peterblazejewicz authored May 11, 2021
1 parent e2785d3 commit ea1c989
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
3 changes: 3 additions & 0 deletions types/money-math/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
export as namespace Money;

export function add(a: string, b: string): string;
export function amountToCents(value: string): string;
export function centsToAmount(value: string): string;
export function subtract(a: string, b: string): string;
export function mul(a: string, b: string): string;
export function div(a: string, b: string): string;
export function percent(a: string, b: string): string;
export function cmp(a: string, b: string): 0 | number;
export function integralPart(value: string): string;
export function isEqual(a: string, b: string): boolean;
export function isZero(value: string): boolean;
export function isNegative(value: string): boolean;
Expand Down
34 changes: 19 additions & 15 deletions types/money-math/money-math-tests.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import * as money from 'money-math';
import money = require("money-math");

money.add("16.11", "17.07"); // "33.18"
money.subtract("16.00", "7.00"); // "9.00"
money.mul("24.00", "0.25"); // "6.00"
money.div("64.00", "2.00"); // "32.00"
money.percent("200.00", "3.25"); // "6.50"
money.cmp("100.00", "200.00"); // -1
money.isEqual("100.00", "100.00"); // true
money.isZero("0.00"); // true
money.isNegative("-1.00"); // true
money.isPositive("-1.00"); // false
money.add("16.11", "17.07"); // $ExpectType string
money.subtract("16.00", "7.00"); // $ExpectType string
money.mul("24.00", "0.25"); // $ExpectType string
money.div("64.00", "2.00"); // $ExpectType string
money.percent("200.00", "3.25"); // $ExpectType string
money.cmp("100.00", "200.00"); // $ExpectType number
money.isEqual("100.00", "100.00"); // $ExpectType boolean
money.isZero("0.00"); // $ExpectType boolean
money.isNegative("-1.00"); // $ExpectType boolean
money.isPositive("-1.00"); // $ExpectType boolean

money.format("JPY", "236800.00"); // "236,800"
money.floatToAmount(56.345); // "56.35"
money.format("JPY", "236800.00"); // $ExpectType string
money.floatToAmount(56.345); // $ExpectType string

money.roundUpTo5Cents("42.02"); // "42.05"
money.roundTo5Cents("442.26"); // "442.25"
money.roundUpTo5Cents("42.02"); // $ExpectType string
money.roundTo5Cents("442.26"); // $ExpectType string

money.integralPart("-55.10"); // $ExpectType string
money.amountToCents("126.99"); // $ExpectType string
money.centsToAmount("10"); // $ExpectType string

0 comments on commit ea1c989

Please sign in to comment.