New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

exframe-decimal

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exframe-decimal

exframe-decimal description

latest
Source
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

Decimal Class

The Decimal class is designed for precise handling of decimal values in JavaScript. It uses BigInt and other mathematical operations to ensure accuracy and avoid common issues with floating-point arithmetic.

Installation

npm install exframe-decimal

Usage

import Decimal from 'decimal-class';

// Create a decimal instance
const decimal = new Decimal(1.23);

// Perform arithmetic operations
const sum = decimal.add(2.45);
const product = decimal.multiply(3.14);
const quotient = decimal.divide(0.5);
const difference = decimal.subtract(0.8);

// Convert decimal to other types
const numberValue = decimal.toNumber();
const stringValue = decimal.toString();

// Specify precision
const rounded = decimal.toDecimalPlaces(2);

// Get absolute value
const absoluteValue = decimal.absolute();

API

new Decimal(value, options?)

Create an instance of the Decimal class. The class is immutable, all operations will return a new insatnce of the Decimal class.

ParameterTypeDescription
valueNumber | Decimal | StringThe decimal value.
options{ precision: Number = 4 }?Optional options to configure the precision of the Decimal.

multiply(decimal: Decimal)

Returns the product of the multiplication of the current and the given Decimal values.

ParameterTypeDescription
decimalDecimalThe second operand.

divide(decimal: Decimal)

Returns the quotient of the division of the current and the given Decimal values.

ParameterTypeDescription
decimalDecimalThe second operand.

add(decimal: Decimal)

Returns the sum of the addition of the current and the given Decimal values.

ParameterTypeDescription
decimalDecimalThe second operand.

subtract(decimal: Decimal)

Returns the difference of the subtraction of the current and the given Decimal values.

ParameterTypeDescription
decimalDecimalThe second operand.

toDecimalPlaces(precision?: Number, options?)

Rounds the current value to the desired precision. If the value is greater than the current precision, it multiplies by 10^difference.

ParameterTypeDescription
precisionNumberThe desired precision.
options{ truncate: Boolean = false }?Optional options to configure the rounding behavior.

truncate()

Truncates the current value to a precision of 0.

absolute()

Returns the absolute value of the current decimal value.

negative()

Returns the inverse of the current decimal value.

FAQs

Package last updated on 06 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts