Skip to content

Rounding / Extensions

Compare
Choose a tag to compare
@varna varna released this 24 Sep 07:12
· 5 commits to master since this release

You can now use rounding function:

import { rounder } from 'measure-ts'
const rounded = rounder(number_of_floating_digits)(value)

You can also get UnitKey or extension from Measure:

describe('unitKey', () => {
  test('m', () => {
    const measure = new Measure(1, 'm')
    expect(measure.unitKey).toBe('m')
  })
  test('cm', () => {
    const measure = new Measure(1, 'cm')
    expect(measure.unitKey).toBe('cm')
  })
  test('m2', () => {
    const measure = new Measure(1, 'm2')
    expect(measure.unitKey).toBe('m2')
  })
  test('cm3', () => {
    const measure = new Measure(1, 'cm3')
    expect(measure.unitKey).toBe('cm3')
  })
})

describe('extension', () => {
  test('m', () => {
    const measure = new Measure(1, 'm')
    expect(measure.extension).toBe('m')
  })
  test('cm', () => {
    const measure = new Measure(1, 'cm')
    expect(measure.extension).toBe('cm')
  })
  test('m2', () => {
    const measure = new Measure(1, 'm2')
    expect(measure.extension).toBe('m²')
  })
  test('cm3', () => {
    const measure = new Measure(1, 'cm3')
    expect(measure.extension).toBe('cm³')
  })
})