moneyFromMajor
moneyFromMajor(
major,currency,minorScale?):Money
Defined in: packages/core/src/money.ts:41
Convert a major-unit amount (e.g. lira, dollars) to Money in integer
minor units. This is the canonical lira→kuruş converter — prefer it over a
hand-rolled Math.round(x * 100), which scatters rounding logic.
Scaling is done in decimal space (via the number’s string form) rather than
by multiplying, so a written decimal like 1.255 rounds the way a human
reads it: Math.round(1.255 * 100) is 125 (because 1.255 * 100 is
125.49999999999999 in IEEE-754), whereas this returns 126. Note this can
only respect the decimal you actually wrote — a literal that is itself
unrepresentable is already lost before the call.
Parameters
Section titled “Parameters”number
currency
Section titled “currency”string
minorScale?
Section titled “minorScale?”number = 2
Returns
Section titled “Returns”Example
Section titled “Example”import { moneyFromMajor, TRY } from '@lonca/core';// A marketplace price of 199.90 ₺:moneyFromMajor(199.9, TRY); // { amount: 19990, currency: 'TRY' } — kuruşmoneyFromMajor(1.255, TRY); // { amount: 126, currency: 'TRY' }Unofficial. Lonca is an independent, community-maintained project — not affiliated with, endorsed by, or supported by Trendyol, Hepsiburada, or any other marketplace. All marketplace names and trademarks belong to their respective owners.