npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

js-precision

v0.1.1

Published

一个基于 Rust + WebAssembly 的高精度计算库,封装了 [`rust_decimal`](https://crates.io/crates/rust_decimal) 实现,支持链式调用、科学计数法和精度控制,适用于前端金融、加密等高精度场景。

Readme

js-precision

🧮 wasm-precision

一个基于 Rust + WebAssembly 的高精度计算库,封装了 rust_decimal 实现,支持链式调用、科学计数法和精度控制,适用于前端金融、加密等高精度场景。


🧬 初始化

import { Precise } from "js-precision";

// 1.使用示例
const result = new Precise("0.1")
  .add("0.2")
  .div("3")
  .to_fixed(8); // => "0.10000000"

console.log(result.value); // 高精度保留结果

// 2.
const r = new Precise('123.456', 3)
    .div('11.327837283')
    .to_fixed();

console.log(r.value); // 按精度截断并补零

创建实例

new Precise(value: string)

创建新的计算实例,支持字符串(包括科学计数法)

Precise.fromNumber(f64)

运算方法(链式)

.add(value: string)
.sub(value: string)
.mul(value: string)
.div(value: string)  // 自动避免除以 0

// 支持基本四则运算
// 所有参数均为字符串,支持科学计数法
// 返回新的 Precise 实例(可链式调用)

精度控制

.with_precision(n: number)

// 设置默认精度,用于 .to_fixed() 时保留的小数位数

值获取

.to_fixed(n?: number)
// 返回保留 n 位小数的字符串,若未传入 n,则使用 .with_precision 设置的默认值
.to_string()
// 返回不做四舍五入的原始字符串
.to_number()
// 转换为 JS 原生 Number 类型(可能有精度损失)
.to_json()
// 返回一个对象结构:
{
    value: string;      // 原始字符串值
    fixed: string;      // 保留小数位后的字符串值
    number: number;     // JS 原生 Number
    precision: number;  // 当前默认精度
}

示例输出

const p = new Precise("1e-7").mul("3").div("2");

console.log(p.to_fixed(12)); // "0.000000150000"
console.log(p.to_json());
{
  "value": "0.00000015",
  "fixed": "0.000000150000",
  "number": 1.5e-7,
  "precision": 12
}