MaplePHP
  • MaplePHP - Layered structure MVC PHP framework
  • Guide
    • Get started
    • Installation
    • Service Provider
    • Dependency injector
    • Controller
    • Middlewares
    • Routers
  • Navigation
    • Simple navigation
    • Dynamic navigation
  • Template engine
    • Getting started
    • Templates
      • Index
      • Views
      • Partials
    • Content (DTO)
      • String
      • Number
      • Array
      • DateTime
      • Encode
      • Dom
  • Form builder
    • Form builder
  • Database
    • MySQL
  • Service providers
    • url
    • encode
    • dir
    • DB
    • responder
  • Installations
    • Authorization & login
  • Frontend template
    • Responder
    • Views & components
    • Modals
    • Redirects
  • Access
    • MaplePHP with Docker
  • Libraries
    • Container
    • MySQL queries
    • Validation
    • Cache
    • Logger
    • Request
    • Response
  • What is?
    • Dependency injector
    • Controller
    • Middleware
    • Router
Powered by GitBook
On this page
  • MaplePHP Format Numbers Library
  • Number Formatting Methods
  • Utility Methods

Was this helpful?

  1. Template engine
  2. Content (DTO)

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.

PreviousStringNextArray

Last updated 1 year ago

Was this helpful?