PHPackages                             arzdigitallabs/reduce-precision - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arzdigitallabs/reduce-precision

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arzdigitallabs/reduce-precision
===============================

A PHP package for reducing precision of numbers.

1103[2 issues](https://github.com/ArzDigitalLabs/reduce-precision/issues)[1 PRs](https://github.com/ArzDigitalLabs/reduce-precision/pulls)TypeScriptCI passing

Since Jul 29Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/ArzDigitalLabs/reduce-precision)[ Packagist](https://packagist.org/packages/arzdigitallabs/reduce-precision)[ RSS](/packages/arzdigitallabs-reduce-precision/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (4)Used By (0)

reduce-precision
================

[](#reduce-precision)

[![Known Vulnerabilities](https://camo.githubusercontent.com/b8ad515f30b8e025db5f27e11960a432a1f9ca3d0f53da0704831482b4f6c68b/68747470733a2f2f736e796b2e696f2f746573742f6769746875622f41727a4469676974616c4c6162732f7265647563652d707265636973696f6e2f62616467652e7376673f74617267657446696c653d7061636b6167652e6a736f6e)](https://snyk.io/test/github/ArzDigitalLabs/reduce-precision?targetFile=package.json)[![Build Status](https://camo.githubusercontent.com/f24fbab991a87147ed914991d2c938ee1e023733e8855c406ae79bdcc694fea3/68747470733a2f2f7472617669732d63692e6f72672f41727a4469676974616c4c6162732f7265647563652d707265636973696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ArzDigitalLabs/reduce-precision)[![codecov.io Code Coverage](https://camo.githubusercontent.com/0d7a8f0fe74cf969f602675ecf5655338a9ad78077449becccf100e5461d4378/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f41727a4469676974616c4c6162732f7265647563652d707265636973696f6e2e7376673f6d61784167653d32353932303030)](https://codecov.io/github/ArzDigitalLabs/reduce-precision?branch=master)[![Code Climate](https://camo.githubusercontent.com/a3f7acd3e556bd4af9e8d489903c82c32e53cce6ba4fbfe3c6f1291606a95464/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f41727a4469676974616c4c6162732f7265647563652d707265636973696f6e2f6261646765732f6770612e737667)](https://codeclimate.com/github/ArzDigitalLabs/reduce-precision)[![NPM Version](https://camo.githubusercontent.com/ff90e5617f38e540cc654c96222089636d151412e45c35a1e438fc0572842d54/68747470733a2f2f62616467652e667572792e696f2f6a732f7265647563652d707265636973696f6e2e7376673f7374796c653d666c6174)](https://npmjs.org/package/reduce-precision)

`reduce-precision` is a versatile package for formatting and reducing the precision of numbers, currencies, and percentages. It supports various templates, precision levels, languages, and output formats, making it easy to generate formatted strings for different use cases.

Features
--------

[](#features)

- Format numbers with customizable precision levels: high, medium, low, or auto
- Support for multiple templates: number, USD, IRT (Iranian Toman), IRR (Iranian Rial), and percent
- Multilingual support: English and Persian (Farsi)
- Output formats: plain text, HTML, and Markdown
- Customizable prefix and postfix markers for HTML and Markdown output
- Intelligent handling of very small and very large numbers
- Automatic thousand separators and decimal points based on the selected language
- TypeScript type definitions included

Installation
------------

[](#installation)

### Node.js / TypeScript

[](#nodejs--typescript)

You can install `reduce-precision` using npm:

```
npm install reduce-precision
```

[![NPM Download Stats](https://camo.githubusercontent.com/754d3fe86da1e1310642fe46d15df22954fc13ca7204f0c41b7497e84fc44247/68747470733a2f2f6e6f6465692e636f2f6e706d2f7265647563652d707265636973696f6e2e706e673f646f776e6c6f6164733d74727565)](https://www.npmjs.com/package/reduce-precision)

### PHP

[](#php)

You can install the PHP version of `reduce-precision` via Composer:

```
composer require arzdigitallabs/reduce-precision
```

Usage
-----

[](#usage)

### Node.js / TypeScript

[](#nodejs--typescript-1)

```
import { NumberFormatter } from 'reduce-precision';

const formatter = new NumberFormatter();

formatter.setLanguage('en', { prefixMarker: 'strong', prefix: 'USD ' });

console.log(formatter.toHtmlString(123456789));
console.log(formatter.toJson(123456789));
console.log(formatter.toString(123456789));
```

### PHP

[](#php-1)

```
require 'vendor/autoload.php';

use NumberFormatter\NumberFormatter;

$formatter = new NumberFormatter();
echo $formatter->toString(12345.678); // Default format
```

Options
-------

[](#options)

The `format` function accepts an optional `options` object with the following properties:

OptionTypeDefaultDescription`precision``'auto'` | `'high'` | `'medium'` | `'low'``'high'`Precision level for formatting`template``'number'` | `'usd'` | `'irt'` | `'irr'` | `'percent'``'number'`Template for formatting`language``'en'` | `'fa'``'en'`Language for formatting (English or Persian)`outputFormat``'plain'` | `'html'` | `'markdown'``'plain'`Output format`prefixMarker``string``'i'`Prefix marker for HTML and Markdown output`postfixMarker``string``'i'`Postfix marker for HTML and Markdown output`prefix``string``''`Prefix string to be added before the formatted number`postfix``string``''`Postfix string to be added after the formatted numberExamples
--------

[](#examples)

### TypeScript/Node.js

[](#typescriptnodejs)

```
import { NumberFormatter } from 'reduce-precision';

// Create a formatter instance with default options
const formatter = new NumberFormatter();

// Basic usage
formatter.setLanguage('en');

// Basic number formatting
formatter.toJson(1234.5678); // Output: { value: '1,234.6', ... }

// Formatting with medium precision
formatter.setTemplate('number', 'medium').toJson(1234.5678); // Output: { value: '1.23K', ... }

// Formatting as USD
formatter.setTemplate('usd', 'high').toJson(1234.5678); // Output: { value: '$1,234.6', ... }

// Formatting as Iranian Rial with Persian numerals
formatter.setLanguage('fa');
formatter.setTemplate('irr', 'medium').toJson(1234.5678); // Output: { value: '۱٫۲۳ هزار ریال', ... }

// Formatting as a percentage with low precision
formatter.setTemplate('percent', 'low').toJson(0.1234); // Output: { value: '0.12%', ... }

// Formatting with HTML output and custom markers
formatter
  .setLanguage('en', { prefixMarker: 'strong', prefix: 'USD ' })
  .toHtmlString(1234.5678);
// Output: USD 1,234.6

// Formatting with string input for small or big numbers
formatter.setTemplate('usd', 'medium').toJson('0.00000000000000000000005678521');
// Output: { value: '$0.0₂₂5678', ... }
```

### PHP

[](#php-2)

```
require 'vendor/autoload.php';

use NumberFormatter\NumberFormatter;

$formatter = new NumberFormatter();
echo $formatter->toString(12345.678); // Default format

$formatter->setLanguage('fa');
echo $formatter->toString(12345.678); // Output in Persian

$formatter->setTemplate('usd', 'high');
echo $formatter->toString(12345.678); // Output in USD format with high precision

echo $formatter->toHtmlString(12345.678);  // HTML formatted output
echo $formatter->toMdString(12345.678);    // Markdown formatted output
```

API
---

[](#api)

### `FormattedObject` Interface (TypeScript/Node.js)

[](#formattedobject-interface-typescriptnodejs)

The `FormattedObject` interface represents the structure of the formatted number object returned by the `format` method.

```
interface FormattedObject {
  value: string; // The formatted value as a string
  prefix: string; // The prefix string
  postfix: string; // The postfix string
  sign: string; // The sign of the number (either an empty string or '-')
  wholeNumber: string; // The whole number part of the value
}
```

### `NumberFormatter` Class (PHP)

[](#numberformatter-class-php)

#### `constructor`

[](#constructor)

Creates a new instance of the `NumberFormatter` class with optional configuration options.

#### `setLanguage`

[](#setlanguage)

Sets the language and optional language configuration for the formatter.

#### `setTemplate`

[](#settemplate)

Sets the template and precision for the formatter.

#### `toString`

[](#tostring)

Formats the input number as a string.

#### `toPlainString`

[](#toplainstring)

Formats the input number as a plain text string.

#### `toHtmlString`

[](#tohtmlstring)

Formats the input number as an HTML string.

#### `toMdString`

[](#tomdstring)

Formats the input number as a Markdown string.

Testing
-------

[](#testing)

### Node.js / TypeScript

[](#nodejs--typescript-2)

You can run tests using Jest or any other preferred testing framework for TypeScript.

### PHP

[](#php-3)

You can run tests using PHPUnit:

```
./vendor/bin/phpunit tests
```

Contributing
------------

[](#contributing)

Contributions are welcome! If you find a bug or have a feature request, please open an issue on the [GitHub repository](https://github.com/ArzDigitalLabs/reduce-precision). If you'd like to contribute code, please fork the repository and submit a pull request.

License
-------

[](#license)

This project is licensed under the [MIT License](LICENSE).

---

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 Bus Factor1

Top contributor holds 61.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/165328528?v=4)[ArzDigital](/maintainers/ArzDigitalLabs)[@ArzDigitalLabs](https://github.com/ArzDigitalLabs)

---

Top Contributors

[![mohammadanaraki](https://avatars.githubusercontent.com/u/28445522?v=4)](https://github.com/mohammadanaraki "mohammadanaraki (38 commits)")[![google-labs-jules[bot]](https://avatars.githubusercontent.com/in/842251?v=4)](https://github.com/google-labs-jules[bot] "google-labs-jules[bot] (8 commits)")[![amirhosseinfaghan](https://avatars.githubusercontent.com/u/56835475?v=4)](https://github.com/amirhosseinfaghan "amirhosseinfaghan (7 commits)")[![nildarar](https://avatars.githubusercontent.com/u/1322066?v=4)](https://github.com/nildarar "nildarar (5 commits)")[![gorfist](https://avatars.githubusercontent.com/u/73386125?v=4)](https://github.com/gorfist "gorfist (2 commits)")[![se8820726](https://avatars.githubusercontent.com/u/3648266?v=4)](https://github.com/se8820726 "se8820726 (2 commits)")

### Embed Badge

![Health badge](/badges/arzdigitallabs-reduce-precision/health.svg)

```
[![Health](https://phpackages.com/badges/arzdigitallabs-reduce-precision/health.svg)](https://phpackages.com/packages/arzdigitallabs-reduce-precision)
```

###  Alternatives

[alleyinteractive/wp-bulk-task

A library to assist with running performant bulk tasks against WordPress objects.

21425.7k5](/packages/alleyinteractive-wp-bulk-task)[infocyph/uid

UUID (RFC 9562), ULID, Snowflake ID, Sonyflake ID, and TBSL generator for PHP.

116.0k](/packages/infocyph-uid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
