Reverse Number
Reverses the digits of a given number while preserving its sign.
reverseNumber
The reverseNumber function reverses the digits of a given number or numeric string. For negative numbers, the negative sign is preserved.
Function Signature
function reverseNumber(num: Numeric): numberParameters
num(Numeric): The number (or numeric string) to be reversed.
Return Value
number: The number with its digits reversed. If the input number is negative, the negative sign is preserved.
Example Usage
playground.ts
Notes
- The function uses
Math.absto safely handle negative values. - It converts the number to a string, reverses the characters, and parses it back to a number.
Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
