Basic Conversion
Install Univerto
First, install the package in your project:For more installation options, see the Installation guide.
Import a Converter
Import the unit converter you need. Univerto uses subpath imports to keep your bundle size minimal:Each converter comes with its own unit constants (e.g.,
TIME_UNIT, LENGTH_UNIT) and converter class (e.g., TimeUnitConverter, LengthUnitConverter).Perform a Conversion
Use the fluent API to convert between units:The API follows a simple pattern:
.from(value, unit)- Specify the source value and unit.to(unit)- Specify the target unit.convert()- Get the converted numeric result
Conversion Methods
Univerto provides three methods for obtaining conversion results:1. convert() - Get Numeric Result
The most common method returns a JavaScript number:
2. convertToFraction() - Get Fraction Object
Get the result as a fraction to avoid floating-point precision issues:
3. convertToRational() - Get Rational Object
Get the internal rational representation with additional methods:
High-Precision Arithmetic
For applications requiring extreme precision, combine Univerto with a decimal library:Univerto internally represents all conversions as fractions to avoid floating-point errors. When you call
convert(), it performs the final division to give you a JavaScript number.Common Examples
Here are some real-world conversion examples:Next Steps
Core Concepts
Learn about the internal architecture and design decisions
Unit Converters
Explore all available unit converters and their supported units