API reference@evolu/commonType › multipleOf

function multipleOf<Divisor>(
  divisor: ValidateMultipleOfDivisor<Divisor>,
): BrandFactory<`MultipleOf${Divisor}`, number, MultipleOfError<Divisor>>;

Defined in: packages/common/src/Type.ts:7260

Number Brand requiring an exact decimal multiple of divisor.

The divisor must be one canonical positive decimal string literal because its exact value is encoded in the resulting Brand name. The declaration is validated at compile time and is never converted to an IEEE-754 number.

Validation treats each finite Number as its canonical decimal representation and checks exact base-10 divisibility. It does not use floating-point remainder, apply a tolerance, or round to the divisor's precision.

Example

import {
  assertEqual,
  assertErr,
  assertOk,
  assertType,
  Data,
  FiniteNumber,
  multipleOf,
  type Brand,
} from "@evolu/common";

const Tenths = multipleOf("0.1")(FiniteNumber);

assertType<FiniteNumber & Brand<"MultipleOf0.1">, typeof Tenths.Output>();

assertOk(Tenths.fromUnknown(0.3), 0.3);
const invalid = Tenths.fromUnknown(0.31);
assertErr(invalid);
assertType(Data, invalid.error);
assertEqual(invalid.error, {
  type: "MultipleOf0.1",
  value: 0.31,
  divisor: "0.1",
});