Skip to main content
Home

Built and signed on GitHub Actions

A deno module, containing relieable custom functions for rounding, ceiling, flooring, truncating and formatting floating point numbers.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
5 months ago (2.0.1)

@codemonument/simple-rounding

JSR

A TypeScript/JavaScript module containing reliable custom functions for rounding, ceiling, flooring, truncating and formatting floating point numbers. Works with Deno, Node.js, Bun, and browsers.

Keywords: rounding, floating-point, precision, math, decimal, ceiling, floor, truncate, typescript, javascript, deno, node, bun

Why?

Basic Problem: JS Floating Point Math is highly inaccurate. Found this thread: https://stackoverflow.com/questions/11832914/how-to-round-to-at-most-2-decimal-places-if-necessary

First best solution: Use a library with correct implementation of floating point math.

Second best solution: Use a custom implementation of roundToPrecision
@bjesuiter original selected implementation (on 2024-09-09):
https://stackoverflow.com/questions/11832914/how-to-round-to-at-most-2-decimal-places-if-necessary#:~:text=Solution%202%3A%20purely%20mathematical%20(Number.EPSILON)

2025-07-11: refined multiple times


Changelog

2.0.1 - 2025-07-27

  • refined examples and published files

2.0.0 - 2025-07-11

  • reworked the whole implementation and added more tests and examples

1.0.0

Initial release


For Contributors

Deploy a new version

  1. Update the version in deno.json
  2. Update all examples & docs
  3. Run deno task test & fix errors
  4. Run deno task dry & fix errors`
  5. Commit, make a tag and push the tag (will then be built by github actions)
Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@codemonument/simple-rounding

Import symbol

import * as simple_rounding from "@codemonument/simple-rounding";
or

Import directly with a jsr specifier

import * as simple_rounding from "jsr:@codemonument/simple-rounding";

Add Package

pnpm i jsr:@codemonument/simple-rounding
or (using pnpm 10.8 or older)
pnpm dlx jsr add @codemonument/simple-rounding

Import symbol

import * as simple_rounding from "@codemonument/simple-rounding";

Add Package

yarn add jsr:@codemonument/simple-rounding
or (using Yarn 4.8 or older)
yarn dlx jsr add @codemonument/simple-rounding

Import symbol

import * as simple_rounding from "@codemonument/simple-rounding";

Add Package

vlt install jsr:@codemonument/simple-rounding

Import symbol

import * as simple_rounding from "@codemonument/simple-rounding";

Add Package

npx jsr add @codemonument/simple-rounding

Import symbol

import * as simple_rounding from "@codemonument/simple-rounding";

Add Package

bunx jsr add @codemonument/simple-rounding

Import symbol

import * as simple_rounding from "@codemonument/simple-rounding";