1

I use blade template and I write:

<div class="col-md-2 col-xs-4 text-right" style="padding:0px;">
  <h2 class="text-theme" style="font-size:36px !important; margin-top:0px !important;">£{{round($product->price,0)}}      <sup style="position: relative;vertical-align: baseline;line-height: 0;font-size: 14px;top: -1.2em;">
    {{number_format($product->price - floor($product->price)),2}}
  </sup>
  </h2>
</div>

and Now I get tc. 96 0

How I can get in <sup> decimal part and if its 0 to be 00 and if its 5 to be 50 ?

Aleks Per
  • 1,549
  • 7
  • 33
  • 68
  • I also try: sscanf(number_format($product->price, 2, ".", ","), '%d.%d', $whole, $fraction); but dont work – Aleks Per Jan 17 '17 at 18:29
  • http://stackoverflow.com/questions/8677805/formatting-numbers-decimal-places-thousands-separators-etc-with-css – Sethmr Jan 17 '17 at 20:46

1 Answers1

0

If you understand this you will understand the function:

    $number = 99.95;

    $explode = explode('.', $number);

    $bike = $explode[0] . "<sup>{$explode[1]}</sup>";

Function version with 0 becomes 00 and 5 becomes 50

public function decimalToExponent($number){
    //place logic somewhere here when the variabel given is not a decimal
    if ( strpos( $number, "." ) == false )
        return null;
    else
    {
        $explode = explode('.', $number); // you get 2 variables $explode[0] = number before '.' $explode[1] number afer .

        if($explode[1] == '0')
        {
            $explode[1] = '00';
        }
        else if($explode[1] == '5')
        {
            $explode[1] = '50';
        }
        return $explode[0] . "<sup>{$explode[1]}</sup>";
    }
}

Make sure that in your blade view you use {!! $variable !!} instead of {{ $variable }} because you want to print as html instead of a string

Mo D Genesis
  • 5,187
  • 1
  • 21
  • 32