PHP Classes

How to Use a PHP Currency Format Class to Represent Money Amounts in the Correct Format Using the Class TCurrencyHandler: Retrieve details and format currency symbol values

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-02-25 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
tcurrencyhandler 1.0Custom (specified...8.4Finances, PHP 8
Description 

Author

This package can retrieve details and format currency symbol values.

It provides a class that can perform several types of operations with money currencies.

Currently it can:

- Get the normalized name of a currency

- Check if a given currency name is valid

- Get the name or symbol of a given currency

- Format a given money amount as a string for a given currency

Picture of Christos Drogidis
  Performance   Level  
Name: Christos Drogidis <contact>
Classes: 37 packages by
Country: Greece Greece
Innovation award
Innovation award
Nominee: 21x

Winner: 4x

Recommendations

What is the best PHP currency symbol class?
Get currency symbol from currency code

Instructions

Please read this document to learn how to perform operations with money currencies.

Example

<?php
/*
dobu {
    file:id(`expl15435`) {
        ascoos {
            name {`ASCOOS OS`},
            version {`1.0.0`},
        },
        example {
            class {`TCurrencyHandler`}
            source {`example.php`},
            category:langs {
                en {`Financials`},
                el {`?????????? ????????`}
            },
            description:langs {
                en {`A complete example of currency management: symbols, names, formatting, validation.`},
                el {`??? ?????? ?????????? ??????????? ??????????: ???????, ?????????, ???????????, ?????????.`}
            },
            author {`Drogidis Christos`},
            sincePHP {`8.4.0`}
        }
    }
}
*/
declare(strict_types=1);

use
ASCOOS\OS\Kernel\Science\Financials\TCurrencyHandler;

// Instance acquisition
$currency = TCurrencyHandler::getInstance();

// 1. Code normalization (normalize)
$code = $currency->normalize('xbt'); // Result: "BTC"
$code = $currency->normalize('rmb'); // Result: "CNY"

// 2. Validity check (isValid)
if ($currency->isValid('EUR')) { // True
   
echo "Valid currency\n";
}
var_dump($currency->isValid('FOO')); // false
echo "\n\n";

// 3. Get Symbol (getSymbol)
echo $currency->getSymbol('USD')."\n"; // $
echo $currency->getSymbol('JPY')."\n"; // ¥
echo $currency->getSymbol('BTC')."\n\n"; // ?

// 4. Get name (getName)
echo $currency->getName('EUR')."\n"; // Euro
echo $currency->getName('EUR', 'el')."\n"; // ????
echo $currency->getName('XBT')."\n\n"; // Bitcoin (ISO?like)


// 5. Amount formatting (format)
echo $currency->format(1234.56, 'USD')."\n"; // $1,234.56
echo $currency->format(1234.56, 'EUR')."\n"; // 1.234,56 ?
echo $currency->format(1234.56, 'JPY')."\n"; // ¥1,235
echo $currency->format(0.12345678, 'BTC')."\n\n"; // ?0.12345678


// 6. Combinational example

$code = 'xbt';

if (
$currency->isValid($code)) {
   
$normalized = $currency->normalize($code);
   
$symbol = $currency->getSymbol($normalized);
   
$name = $currency->getName($normalized, 'el');
   
$formatted = $currency->format(0.05, $normalized);

    echo
"Currency: $name\n";
    echo
"Code: $normalized\n";
    echo
"Symbol: $symbol\n";
    echo
"Amount: $formatted\n\n";
}
/*
Result:
Currency: ????????
Code: BTC
Symbol: ?
Amount: ?0.05000000
*/


// 7. Exception handling
try {
    echo
$currency->getSymbol('FOO');
} catch (
ValueError $e) {
    echo
"Error: " . $e->getMessage();
}
?>


Details

ASCOOS OS ? TCurrencyHandler

A complete, modular currency management handler for the ASCOOS Web Operating System.

The class is part of the collection of about 1,500 classes that make up the ASCOOS OS.

Ascoos

Table of Contents

Overview

TCurrencyHandler is the first publicly released class (with open source) of ASCOOS OS, designed to demonstrate:

  • the architecture and coding style of the ASCOOS Kernel
  • the optional classes dynamic loading system (Extras Classes Manager)
  • the DoBu documentation technology
  • and a fully functional, production?ready currency management module

This class provides:

  • currency symbols
  • currency names (EN/EL)
  • formatting rules
  • validation
  • normalization (aliases)
  • crypto support
  • ISO?4217 support (active + deprecated)

Features

  • ? ISO?4217 currency support
  • ? Deprecated currency support
  • ? Crypto currency support
  • ? Multilingual names (EN/EL)
  • ? Symbol lookup
  • ? Amount formatting
  • ? Normalization via aliases
  • ? Validation
  • ? UTF?8 safe
  • ? Fully documented with DoBu
  • ? Optional loading via Extras Manager

Installation

This class is part of the ASCOOS OS Extras Kernel Classes system and does not require installation as it already exists in the kernel.

Namespace

use ASCOOS\OS\Kernel\Science\Financials\TCurrencyHandler;

Management

It is loaded dynamically by the internal app Extras Classes Manager, depending on user configuration.

ASCOOS OS

DoBu Documentation

This repository includes full DoBu docblocks for:

  • the file with the class and the example file
  • the class
  • each method
  • parameters
  • return types
  • exceptions
  • multilingual descriptions

DoBu is the official documentation DSL of ASCOOS OS.

DoBu documentation in the example file

/*
dobu {
    file:id(`expl15435`) {
        ascoos {
            name {`ASCOOS OS`},
            version {`1.0.0`},
        },
        example {
            class {`TCurrencyHandler`}
            source {`example.php`},
            category:langs {
                en {`Financials`},
                el {`?????????? ????????`}
            },
            description:langs {
                en {`A complete example of currency management: symbols, names, formatting, validation.`},
                el {`??? ?????? ?????????? ??????????? ??????????: ???????, ?????????, ???????????, ?????????.`}
            },
            author {`Drogidis Christos`},
            sincePHP {`8.4.0`}
        }
    }
}
*/

Usage Example

use ASCOOS\OS\Kernel\Science\Financials\TCurrencyHandler;

$currency = TCurrencyHandler::getInstance();

// Normalize
echo $currency->normalize('xbt'); // BTC

// Validate
var_dump($currency->isValid('EUR')); // true

// Symbol
echo $currency->getSymbol('USD'); // $

// Name
echo $currency->getName('EUR', 'el'); // ????

// Format
echo $currency->format(1234.56, 'EUR'); // 1.234,56 ?

See the full example: example.php which produces the following result

ASCOOS OS

Architecture Notes

ASCOOS OS uses a Full Modular Kernel Architecture:

  • Some classes are Deep Core Kernel (always loaded)
  • Others are Extras (optional, dynamically loaded)
  • Namespace does not reflect physical path
  • Extras Manager handles: - dependency resolution - selective loading - performance optimization

TCurrencyHandler is a Kernel Science class, but loaded as an Extra.

License

AGL (ASCOOS General License)

Author

Drogidis Christos ASCOOS OS Creator https://www.ascoos.com


  Files folder image Files (10)  
File Role Description
Files folder imageconfig (1 directory)
Files folder imageextras (1 directory)
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE-EL.md Lic. License text
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README-EL.md Doc. Documentation
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (10)  /  config  
File Role Description
Files folder imagecurrency (4 files)

  Files folder image Files (10)  /  config  /  currency  
File Role Description
  Accessible without login Plain text file aliases.php Conf. Configuration script
  Accessible without login Plain text file formats.php Conf. Configuration script
  Accessible without login Plain text file names.php Conf. Configuration script
  Accessible without login Plain text file symbols.php Conf. Configuration script

  Files folder image Files (10)  /  extras  
File Role Description
Files folder imagescience (1 directory)

  Files folder image Files (10)  /  extras  /  science  
File Role Description
Files folder imagefinancials (1 file)

  Files folder image Files (10)  /  extras  /  science  /  financials  
File Role Description
  Plain text file coreCurrency.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadtcurrencyhandler-2026-02-25.zip 18KB
Downloadtcurrencyhandler-2026-02-25.tar.gz 15KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Ascoos OS Download .zip .tar.gz Uses Ascoos OS Kernel Required
 Version Control Unique User Downloads  
 100%
Total:0
This week:0