本文整理汇总了TypeScript中src/lib/number.toRound函数的典型用法代码示例。如果您正苦于以下问题:TypeScript toRound函数的具体用法?TypeScript toRound怎么用?TypeScript toRound使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toRound函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('toRound(), 以有效数字的位数对数字进行四舍五入', () => {
expect(toRound(123456789)).toBe(123457000);
expect(toRound(123.456789)).toBe(123.457);
expect(toRound(-123.456789)).toBe(-123.457);
expect(toRound(0.123456789)).toBe(0.123457);
expect(toRound(0.00123456789)).toBe(0.00123457);
expect(toRound(0.00123456789, 2)).toBe(0.0012);
expect(toRound(-0.00123456789, 2)).toBe(-0.0012);
expect(toRound(0.00123456789, 8)).toBe(0.0012345679);
expect(() => toRound(NaN)).toThrowError('(number) Cannot run toRound(NaN)');
});
示例2: expect
expect(new Point(1, 1).toUnit().map((n, i) => toRound(n, 8))).toEqual([0.70710678, 0.70710678]);
示例3: test
test('Point.prototype.product()', () => {
const node = new Point(1, 2);
expect(node.product([2, 4])).toEqual(10);
expect(toRound(node.product([0.1, 0.8]))).toEqual(1.7);
});
示例4: expect
expect(() => toRound(NaN)).toThrowError('(number) Cannot run toRound(NaN)');