Announcement

Collapse
No announcement yet.

decimal places

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

    decimal places

    Hi,

    I have two problems which are pretty similar.

    1. I use some java to work out how much money is needed till free delivery. If the figure ends with a 0 it drops it (so 23.90 is 23.9 and 23.00 becomes just 23).

    2. I also have this problem with actinic variable as well. I have a var as a number (not whole numbers only) and in that I have a RRP. If its 25.50 then it gets displayed as 25.5 and 25.00 becomes 25.

    Any idea how I can fix these? I guess the second one is some php?

    Paul.

    #2
    research the ToFixed function in each language
    Bill
    www.egyptianwonders.co.uk
    Text directoryWorldwide Actinic(TM) shops
    BC Ness Solutions Support services, custom software
    Registered Microsoft™ Partner (ISV)
    VoIP UK: 0131 208 0605
    Located: Alexandria, EGYPT

    Comment


      #3
      thanks bill - off i go

      Comment


        #4
        And if you want to stick in commas every thousand
        Code:
        function CommaFormatted(num){
          var sep = ',';
          num = num.toString().split('').reverse().join('');		// reverse number
          num = num.replace(/(\d\d\d)(?=\d)(?!\d*\.)/g,'$1' + sep);	// add commas
          return num.split('').reverse().join('');			// reverse number back;
        }
        
        // example
        var n = 10001.1;
        alert(CommaFormatted(n.toFixed(2)));
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          lol, reverse engineering - nice!

          Comment


            #6
            Hi guys, I have successfully got the java working but I have yet to find a solution in php. I find it somewhat annoying that actinic strips the 0 off in the first place (its there in the variable)... i guess its something to do with it using php to make the pages?

            anyhoo, any ideas with php?

            thanks,
            paul.

            p.s. thats a useful script norman - i am adding it to my repository... now if we had a wiki

            Comment


              #7
              Try the PHP documentation for printf , sprintf or money_format.

              PS the JavaScript above could be written on one line but it would be way too long to understand.
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment


                #8
                Hi guys, for completeness, here is my code that does what I want...
                PHP Code:
                <actinic:block php="true" >
                  
                $rrp '<actinic:variable name="Prod_All_RRP" />';
                  
                $saved $rrp '<actinic:variable name="ProductPriceRaw" />';
                  
                $rrp sprintf('%01.2f'$rrp);
                  
                $saved sprintf('%01.2f'$saved);
                  echo 
                'You Save! RRP is £' $rrp ', saving you <b>£' $saved '!</b>';
                  unset(
                $rrp);
                  unset(
                $saved);
                </
                actinic:block
                it outputs:
                You Save! RRP is £45.50, saving you £16.50!
                thanks again for everyones help,

                paul.

                Comment

                Working...
                X