MCPcopy
hub / github.com/formatjs/formatjs / floor

Method floor

packages/bigdecimal/index.ts:408–430  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

406 }
407
408 floor(): BigDecimal {
409 if (this._special !== SpecialValue.NONE) return this
410 if (this._mantissa === 0n) return this
411 if (this._exponent >= 0) return this // already an integer
412
413 const divisor = bigintPow10(-this._exponent)
414 const m = this._mantissa
415 let q = m / divisor
416
417 // Floor: round toward -infinity
418 // For negative numbers with remainder, subtract 1
419 if (m < 0n && m % divisor !== 0n) {
420 q -= 1n
421 }
422
423 if (q === 0n) {
424 // Check if we should return -0
425 const negZero = this._mantissa < 0n
426 return BigDecimal._create(0n, 0, SpecialValue.NONE, negZero)
427 }
428 const [nm, ne] = removeTrailingZeros(q, 0)
429 return BigDecimal._create(nm, ne, SpecialValue.NONE, false)
430 }
431
432 ceil(): BigDecimal {
433 if (this._special !== SpecialValue.NONE) return this

Callers 15

bigdecimal.test.tsFile · 0.80
DefaultNumberOptionFunction · 0.80
offsetToGmtStringFunction · 0.80
FormatDateTimePatternFunction · 0.80
ResolvePluralInternalFunction · 0.80
ComputeExponentFunction · 0.80
findN1E1R1Function · 0.80
findN2E2R2Function · 0.80
findN1R1Function · 0.80
ToIntegerFunction · 0.80

Calls 3

bigintPow10Function · 0.85
removeTrailingZerosFunction · 0.85
_createMethod · 0.80

Tested by

no test coverage detected