当前位置: 动力学知识库 > 问答 > 编程问答 >

Format after multiplying in php

问题描述:

I do not know how to format after multiplying.

Example:

0.012333 * 3.500

Always zero left would be a fee.

Is there a way to format this 0.012333 after multiplying?

网友答案:

As someone rightly noted in the comments section of your Post, the result of multiplying 0.012333 by 3.500 would be 0.0431655. However, if by Format You want to mean Formatting the Result (0.0431655) to some friendly-looking Figures, then you may want to consider working with PHP's number_format() Function which will return a String, given a Floating Point Number like 0.0431655. The Snippet below demonstrates this:

<?php

    $result     = 0.012333 * 3.500;
    $formatted  = number_format($result, 2, '.', ',');

    var_dump($result);        //<== YIELDS:: float 0.0431655 
    var_dump($formatted);     //<== YIELDS:: string '0.04' (length=4)
分享给朋友:
您可能感兴趣的文章:
随机阅读: