A TypeScript library for converting numbers to various scientific notation formats
npm install @sctg/scientific-notationA TypeScript library for formatting numbers in various scientific notation representations including HTML, LaTeX, and MathML.
- Convert numbers to scientific notation with configurable precision
- Multiple output formats:
- Standard scientific notation (e.g., 1.23e6)
- LaTeX (1.23 \times 10^{6})
- MathML ()
- HTML (1.23 × 106)
- Precise control over significant figures
- Standardized exponents (steps of 3)
- Zero handling
- Typescript types included
``bash`
npm install @sctg/scientific-notation
`typescript
import { ScientificNotation } from '@sctg/scientific-notation';
// Basic usage
const number = 1234567.89;
const precision = 4;
// Standard scientific notation
console.log(ScientificNotation.toScientificNotationString(number, precision));
// Output: "1.235e6"
// LaTeX format
console.log(ScientificNotation.toScientificNotationLatex(number, precision));
// Output: "1.235 \times 10^{6}"
// HTML format
console.log(ScientificNotation.toScientificNotationHTML(number, precision));
// Output: "1.235 × 106"
// MathML format
console.log(ScientificNotation.toScientificNotationMathML(number, precision));
// Output: ""
`
Converts a number to scientific notation components.
`typescript`
const result = ScientificNotation.toScientificNotation(1234.56, 3);
// Returns: { mantissa: 1.23, exponent: 3 }
Returns a string representation in scientific notation.
Returns a LaTeX formatted string.
Returns a MathML formatted string.
Returns an HTML formatted string.
`typescript`
type ScientificNotationNumber = {
mantissa: number; // The coefficient
exponent: number; // The power of 10
};
- Standardizes exponents in steps of 3
- Maintains precision with trailing zeros
- Handles special cases (zero, small numbers)
- Type-safe with TypeScript
1. Fork the repository
2. Create your feature branch (git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature'
3. Commit your changes ()git push origin feature/amazing-feature`)
4. Push to the branch (
5. Open a Pull Request
Copyright (c) 2024-2025 Ronan LE MEILLAT
This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details.
Ronan LE MEILLAT
SCTG Development
- @sctg/aga8-js - GERG-2008 equations of state
- flow-dilution - Gas flow dilution calculator