Hyperlinkv0.8.0-beta.28

BigDecimal

BigDecimal.Equivalenceconsteffect/BigDecimal.ts:1193
(self: BigDecimal, that: BigDecimal): boolean

Provides an Equivalence instance for BigDecimal that determines equality between BigDecimal values.

When to use

Use when comparing decimal values through APIs that accept an equivalence relation.

Example (Checking decimal equivalence)

import { BigDecimal } from "effect"

const a = BigDecimal.fromStringUnsafe("1.50")
const b = BigDecimal.fromStringUnsafe("1.5")
const c = BigDecimal.fromStringUnsafe("2.0")

console.log(BigDecimal.Equivalence(a, b)) // true (1.50 === 1.5)
console.log(BigDecimal.Equivalence(a, c)) // false (1.50 !== 2.0)
instances
export const Equivalence: Equ.Equivalence<BigDecimal> = Equ.make((self, that) => {
  if (self.scale > that.scale) {
    return scale(that, self.scale).value === self.value
  }

  if (self.scale < that.scale) {
    return scale(self, that.scale).value === that.value
  }

  return self.value === that.value
})
Referenced by 2 symbols