本文整理匯總了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)');