@editorialapp/datatools
Version:
A collection of dependencies organized into useful tools for working with data in ways that are common in data cleaning and in building news apps.
30 lines (22 loc) • 692 B
JavaScript
import { test } from 'brittle'
import { format_number, format_percentage, round_decimal } from '../lib/numbers.js'
test('round_decimal', async (t) => {
const one = round_decimal(1.23456789, 2)
t.is(one, 1.23)
const two = round_decimal(1.23456789, 3)
t.is(two, 1.235)
const three = round_decimal(1.327)
t.is(three, 1.33)
})
test('format_percentage', async (t) => {
const one = format_percentage(0.123456789)
t.is(one, '12.35%')
const two = format_percentage(0.5432115, 3)
t.is(two, '54.321%')
})
test('format_number', async (t) => {
const one = format_number(123456789)
t.is(one, '123,456,789')
const two = format_number(123456789.1234567)
t.is(two, '123,456,789.123')
})