Rounding in formula

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tothewine
    Active Community Member
    • Jan 2018
    • 408

    #1

    Rounding in formula

    How do I get a formula without rounding?
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1816

    #2
    By default calculating interger and float happens without rounding. In float, you have to set the needed amount of decimals in the field itself.

    Comment

    • tothewine
      Active Community Member
      • Jan 2018
      • 408

      #3
      this is the result of this formula

      suPrezzoPromo = number\format((((importoOffertaIvaEsclusa/prezzoCodiceIvaEsclusa)-1)*100));


      Click image for larger version

Name:	image.png
Views:	0
Size:	9.9 KB
ID:	123779
      with this field setting

      Click image for larger version

Name:	image.png
Views:	0
Size:	18.8 KB
ID:	123780

      Comment

      • shalmaxb
        Senior Member
        • Mar 2015
        • 1816

        #4
        Guessing from your example, you have an article with normal price, which you offer also as promo with a percentage (both adding% and substracting% ??).

        So from the normal price you set any + or - percentage and then want to display the promo price.

        If this is the case, you do not need formatting formula, it is more simple:

        PHP Code:
        suPrezzoPromo normalPrice + ((normalPrice/100)*percentValue); 
        If you input a positive value, the percentage amount will be added to the normal price. If you input a negative value, it will be substracted.

        Your examples, calculated with this formula:

        5420,00 1% 5474,20
        4000,00 -5% 3800,00
        3800,00 18% 4720,00
        3800,00 0% 3800,00

        I hope it helps.

        Comment

        • tothewine
          Active Community Member
          • Jan 2018
          • 408

          #5
          exactly, I have the two prices as a reference and I have to find the percentage discount and the result is always rounded

          Comment

          • shalmaxb
            Senior Member
            • Mar 2015
            • 1816

            #6
            ok, so you want to know the percentage difference between the two reference prices? The percentage value should be the result and that without rounding?

            If so, again, you do not need formula format. You just need to calculate the difference from price1 to price2 and concert that in the formula to percent.

            But it is still not clear, what you want to achieve.

            Comment

            Working...