CKN Technology Core · Number Extensions

CKN Technology Core
Number Extensions

This page documents all extended Number.prototype functions from @ckn-technology/core, including console helpers, formatting, math utilities, conversion helpers, range mapping and angle conversion.

Import

To load and enable the custom Number extensions, import the core module once at your application entry point. This registers the extensions globally on Number.prototype.

import "@ckn-technology/core";

All examples on this page assume this import has already been executed at application startup.

1. Console & Formatting

print()

Description
Logs the number to console.log() and returns the original Number object, allowing further chaining.

Signature

print(): Number

Example

(123).print();  // logs: 123

round()

Description
Rounds the number to the nearest integer using Math.round.

Signature

round(): Number

Example

(4.6).round();   // 5
(4.4).round();   // 4

ceil()

Description
Rounds the number up to the nearest integer using Math.ceil.

Signature

ceil(): Number

Example

(4.1).ceil();   // 5

floor()

Description
Rounds the number down to the nearest integer using Math.floor.

Signature

floor(): Number

Example

(4.9).floor();   // 4

printFormat(decimal_number, separate_thousands = ",")

Description
Formats a number with a fixed number of decimal places and a thousands separator. Useful for displaying amounts, KPIs, and financial values in a human-friendly style.

Signature

printFormat(decimal_number: number, separate_thousands?: string): string

Example

(12345.678).printFormat(2);  
// "12,345.68"

2. Padding (via String.padLeft / padRight)

padStart(targetLength, padString)

Description
Pads the number on the left by first converting it to a string and then delegating to String.prototype.padLeft.

Signature

padStart(targetLength: number, padString: string): string

Example

(5).padStart(3, "0");   // "005"

padEnd(targetLength, padString)

Description
Pads the number on the right using String.prototype.padRight internally.

Signature

padEnd(targetLength: number, padString: string): string

Example

(5).padEnd(3, "0");   // "500"

3. Core Math Utilities

abs()

Description
Returns the absolute value of the number.

Signature

abs(): number

Example

(-5).abs();   // 5

clamp(min, max)

Description
Clamps the number into the inclusive range [min, max]. Values below min become min; values above max become max.

Signature

clamp(min: number, max: number): number

Example

(15).clamp(0, 10);  // 10

between(min, max, inclusive = true)

Description
Checks if the number is between min and max. If inclusive is true, uses ≤ / ≥; otherwise uses strict < / >.

Signature

between(min: number, max: number, inclusive?: boolean): boolean

Example

(5).between(1, 10);         // true
(10).between(1, 10, false); // false

isInt()

Description
Checks whether the number is an integer (no fractional part).

Signature

isInt(): boolean

Example

(5).isInt();     // true
(5.2).isInt();   // false

isPositive()

Description
Returns true if the number is strictly greater than 0.

Signature

isPositive(): boolean

Example

(3).isPositive();  // true

isNegative()

Description
Returns true if the number is strictly less than 0.

Signature

isNegative(): boolean

Example

(-1).isNegative();   // true

isZero()

Description
Checks if the number is exactly 0.

Signature

isZero(): boolean

Example

(0).isZero();  // true

sign()

Description
Returns -1 if the number is negative, 0 if it is zero, and 1 if it is positive – mirroring Math.sign semantics.

Signature

sign(): number

Example

(-5).sign();   // -1
(0).sign();    // 0
(7).sign();    // 1

4. Conversion Helpers

toFixedNumber(decimal_number)

Description
Similar to native toFixed, but returns a number instead of a string, making it easier to continue math operations.

Signature

toFixedNumber(decimal_number: number): number

Example

(1.2345).toFixedNumber(2);  // 1.23

toPercent(decimal_number = 2)

Description
Converts a decimal value to a percentage string, multiplying by 100 and appending "%". Decimal places can be controlled via the parameter.

Signature

toPercent(decimal_number?: number): string

Example

(0.1234).toPercent(2);   // "12.34%"

5. Mapping & Ranges

map(inMin, inMax, outMin, outMax)

Description
Maps a number from one range to another. Often used for scaling values (e.g. from a sensor range to a UI range, or normalizing scores).

Signature

map(
  inMin: number,
  inMax: number,
  outMin: number,
  outMax: number
): number

Example

(5).map(0, 10, 0, 100);  // 50

6. Angle Conversion

toRad()

Description
Treats the current number as degrees and converts it to radians.

Signature

toRad(): number

Example

(180).toRad();   // 3.14159...

toDeg()

Description
Treats the current number as radians and converts it to degrees.

Signature

toDeg(): number

Example

(Math.PI).toDeg();   // 180

Summary

The CKN Technology Core | Number Extensions enrich the native JavaScript Number type with a concise toolkit for logging, formatting, padding, validation, classification, percent and fixed-point conversion, range mapping, and angle transformation. These helpers make numeric workflows more expressive and consistent across your applications, while keeping implementation code short and easy to read.