Number

MaplePHP Format Numbers Library

This PHP library, named MaplePHP\DTO\Format\Num, provides functionality for formatting numbers. Below is a guide to the methods available in this library.

Number Formatting Methods

float(): self

  • Converts the value to a float number.

int(): self

  • Converts the value to an integer.

round(int $dec = 0): self

  • Rounds the number to a specified number of decimal places.

  • Parameters:

    • $dec: Number of decimal places.

floor(): self

  • Rounds down the floating-point value to the nearest integer.

ceil(): self

  • Rounds up the floating-point value to the nearest integer.

toKb(): self

  • Converts the value to kilobytes.

toFilesize(): self

  • Formats the value to an appropriate file size ending (k, M, G, T).

toBytes(): self

  • Converts the value to bytes.

currency(string $currency, int $decimals = 2): FormatInterface

  • Formats the number as a currency.

  • Parameters:

    • $currency: The currency code (e.g., SEK, EUR).

    • $decimals: Number of decimal places for rounding.

  • Returns:

    • An instance of FormatInterface (uses NumberFormatter and Str classes).

Utility Methods

numFormatter(): \NumberFormatter

  • Provides a shared instance of \NumberFormatter for number formatting.

Last updated