【问题标题】:How to show decimal part in <sup> tag如何在 <sup> 标签中显示小数部分
【发布时间】:2017-06-01 22:38:10
【问题描述】:

我使用刀片模板并编写:

<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>

现在我得到了 tc。 96 0

我如何获得&lt;sup&gt; 小数部分,如果它的 0 是 00,如果它的 5 是 50?

【问题讨论】:

标签: php html blade number-formatting


【解决方案1】:

如果你理解了这个你就会明白这个函数:

    $number = 99.95;

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

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

0 变成 00 和 5 变成 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>";
    }
}

确保在刀片视图中使用 {!! $variable !!} 而不是 {{ $variable }} 因为您想将 打印为 html 而不是字符串

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    相关资源
    最近更新 更多