Click here for v1.x documentation.
Dinero.js
Dinero.js version

toDecimal

TOutput = string

Get the amount of a Dinero object in a stringified decimal representation.

The number of decimal places depends on the scale of your object—or, when unspecified, the exponent of its currency.

Copy linkParameters

NameTypeDescriptionRequired
dineroObjectDinero<TAmount>

The Dinero object to format.

Yes
transformerTransformer<TAmount, TOutput>

An optional transformer function.

No

Copy linkCode examples

Copy linkFormat an object in decimal format

import { dinero, toDecimal } from 'dinero.js';
import { USD } from '@dinero.js/currencies';

const d1 = dinero({ amount: 1050, currency: USD });
const d2 = dinero({ amount: 10545, currency: USD, scale: 3 });

toDecimal(d1); // "10.50"
toDecimal(d2); // "10.545"

Copy linkUse a custom transformer

If you need to further transform the value before returning it, you can pass a custom function.

import { dinero, toDecimal } from 'dinero.js';
import { USD } from '@dinero.js/currencies';

const d = dinero({ amount: 1050, currency: USD });

toDecimal(d, ({ value, currency }) => `${currency.code} ${value}`); // "USD 10.50"