Announcement

Collapse
No announcement yet.

Show two decimal places

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Show two decimal places

    I have a user variable of RRP. It shows correctly if the value is 8.55, however if the value is 8.00 it shows as 8 and if it is 8.10 is shows as 8.1.

    How can I make the number displayed always have two decimal places?

    #2
    Use 'text' not 'number' is the easy way.

    Comment


      #3
      Assuming variable RRP is of type number:
      Code:
      <actinic:block php="true">printf('%.2f',<actinic:variable name="RRP" />);</actinic:block>
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        Originally posted by leehack View Post
        Use 'text' not 'number' is the easy way.
        I have to admit, this is what I do.
        That way you have more control over how it is displayed.
        Tracey

        Comment


          #5
          Simplest is often best .

          Comment


            #6
            Thank you for all your answers - the number can not be fomatted as text as it is linked to another database, I will try the other method and let you know how I get on.

            Comment


              #7
              Hi
              Sorry to bump this to the top after all this time but I have the same problem. Bottom line, Im trying to add the AUG Automatically Calculate Savings based on an RRP code but if you have a RRP of 43.50 for example, it shows it as 43.5
              .
              I cant change the field type to text as php requires it as a number and I cant seem to find the exact format of the printf as per Normans post as code is already in php.
              Thanks in adance for any help.
              K

              Comment


                #8
                Kevin

                If the code you're using contains this line:
                Code:
                echo "RRP £$rrp - you save $savepercent%";
                Try changing it to:
                Code:
                printf('RRP £%.2f  - you save %u%%', $rrp, $savepercent);
                If it's different, post the code you're trying to use so we can point out where to fix it.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  Thanks, worked a treat.

                  Comment

                  Working...
                  X