HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/honger7.komma.pro/app/KommaApp/Facades/Format.php
<?php

namespace App\KommaApp\Facades;

use Illuminate\Support\Facades\Facade;

class Format extends Facade
{
    protected static function getFacadeAccessor()
    {
        return 'format';
    }


    /**
     * Format input as price
     *
     * @param $input
     * @param array $options
     * @return string
     */
    static public function asPrice($input, $options = ['currency' => ''])
    {
        $decimals = false;

        $output = '';
        if( ! empty($options['currency'])) $output .= '<span class="currency">' . htmlentities($options['currency']) . '</span>';

        $input = (string) $input / 100;
        //Only show two decimals
        $input = number_format($input,2);

        $parts = explode('.',$input);

        // Check units
        $units = $parts[0];

        // Check decimals
        if( isset($parts[1]) )
        {
            $decimals = $parts[1];
            $decimals = str_pad($decimals, 2, '0', STR_PAD_RIGHT);
        }
        else
        {
            $decimals = '00';
        }

        // Loop through units
        foreach(str_split($units) as $char)
        {
            $output .= '<span class="unit">' . $char . '</span>';
        }

        $output .= '<span class="point">,</span>';

        // Loop through decimals
        foreach(str_split($decimals) as $char)
        {
            $output .= '<span class="decimal">' . $char . '</span>';
        }
        return $output;
    }

    static public function asFlatPrice($input, $options = ['currency' => ''])
    {
        if(! is_numeric($input)) return $input;
        $output = number_format($input / 100, 2, ',', '');
        if($options['currency']) $output = $options['currency'] . ' ' . $output;
        return $output;
    }

    static public function asPercentage($input)
    {
        if(! is_numeric($input)) return $input;
        return round($input * 100) / 100;
    }
}