Numeric Input/Output Utilities
The numeric-utils.js module provides essential utilities for handling numeric input/output in web forms, especially for floating-point values with special cases.
Purpose
The utilities solve the common problem of handling special numeric values (Infinity, -Infinity, NaN) in JSON serialization and user interfaces. JavaScript's JSON.stringify converts these special values to null or strings, which can cause issues when communicating with C# backend APIs. This module provides consistent conversion between numeric values and display strings, ensuring proper handling across the full stack. It also formats regular numbers with appropriate precision for display while avoiding unnecessary trailing zeros.
Key Features
- Converts Infinity to “INF”, -Infinity to “-INF”, and NaN to “NaN” for display
- Parses these special strings back to their numeric equivalents
- Formats regular numbers with appropriate precision (4 significant digits)
- Provides a Vue mixin for easy integration in components
- Handles both numeric and string inputs from JSON responses