New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@sctg/scientific-notation

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sctg/scientific-notation

A TypeScript library for converting numbers to various scientific notation formats

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
0
Created
Source

Scientific Notation Formatter

A TypeScript library for formatting numbers in various scientific notation representations including HTML, LaTeX, and MathML.

Features

  • 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 (<math><mrow><mn>1.23</mn><mo>×</mo><msup><mn>10</mn><mn>6</mn></msup></mrow></math>)
    • HTML (1.23 × 10<sup>6</sup>)
  • Precise control over significant figures
  • Standardized exponents (steps of 3)
  • Zero handling
  • Typescript types included

Installation

npm install @sctg/scientific-notation

Usage

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 × 10<sup>6</sup>"

// MathML format
console.log(ScientificNotation.toScientificNotationMathML(number, precision));
// Output: "<math><mrow><mn>1.235</mn><mo>×</mo><msup><mn>10</mn><mn>6</mn></msup></mrow></math>"

API Reference

toScientificNotation(value: number, precision?: number): ScientificNotationNumber

Converts a number to scientific notation components.

const result = ScientificNotation.toScientificNotation(1234.56, 3);
// Returns: { mantissa: 1.23, exponent: 3 }

toScientificNotationString(value: number, precision?: number): string

Returns a string representation in scientific notation.

toScientificNotationLatex(value: number, precision?: number): string

Returns a LaTeX formatted string.

toScientificNotationMathML(value: number, precision?: number): string

Returns a MathML formatted string.

toScientificNotationHTML(value: number, precision?: number): string

Returns an HTML formatted string.

Types

type ScientificNotationNumber = {
  mantissa: number;  // The coefficient
  exponent: number;  // The power of 10
};

Features

  • Standardizes exponents in steps of 3
  • Maintains precision with trailing zeros
  • Handles special cases (zero, small numbers)
  • Type-safe with TypeScript

Contributing

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add some amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

License

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.

Author

Ronan LE MEILLAT
SCTG Development

Keywords

scientific-notation

FAQs

Package last updated on 24 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts