0

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?

Conseld
  • 47
  • 1
  • 10
  • How do you want it formatted? example, what do you want the result to look like? –  Dec 06 '16 at 18:05
  • Is it possible to multiply like this? 0.012333 * 3.500 Do you see any results? – Conseld Dec 06 '16 at 18:10
  • 0.012333*3.500=0.0431655... if you type `echo 0.012333*3.5000;` php will calculate it, and print out 0.0431655. is that what you're trying to achieve? I have a difficulty understanding your question. –  Dec 06 '16 at 18:13
  • Sorry, I'll try to explain. I have this number 0.012332 when I make 0.012333 * $ 3,500.00 = 0 $ValueTotal = $listar3->date["house"] * $rate1->date["rateTaxa"]; Is it correct and format 0,012332 to give a whole number? – Conseld Dec 06 '16 at 18:23
  • @Stefanato You are **multiplying a String by a Float**. ***The result would thus be 0*** `$ 3,500.00` seem like a String. Most likely, you need to convert that `$ 3,500.00` to either a `Float`, a `Double` or any `Number` Data-Type. Once that is done, your multiplication should work without throwing unexpected results at you. ***Just keep in mind that in PHP multiplying a Numeric value by a String always returns 0!*** – Poiz Dec 06 '16 at 18:32
  • As @Poiz notes... you will have to convert the string to a number. see the answers to this question, on how to achieve that. http://stackoverflow.com/questions/6278296/extract-numbers-from-a-string –  Dec 06 '16 at 18:33

1 Answers1

0

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)
Poiz
  • 7,611
  • 2
  • 15
  • 17