Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2014
    Thanked 0 Times in 0 Posts

    How do I format the number of decimal places in a table?

    Hi folks!

    Apologies if this is obvious, but nothing I seem to do is working for me. Also, apologies if this is in the wrong place!

    I have a website that incorporates a shopping cart. The prices , in the cart are formatted in GBP. The eventual output of the cart is being passed through to my payment option, via a form, as [ORDER_NO] and [PRICE].

    All is well with the Order No, but the Price field seems to be displayed with 3 decimal places (e.g. 150.000) instead of 2! Is there a way of defining the number of decimal places to only 2? I've tried using the toFixed option, but I can't seem to make it work! Grrrrr!

    My code, for that part of the form, is as follows:

    <script language=JavaScript>

    <!-- This defines the fixed products price as an example. -->
    function price(x)
    document.form.amount.value = x;



    <h1>Customer Details</h1>

    <!-- A table displaying the fixed example product. -->
    <table border="2" cellpadding="3" align="center">
    <td>Order Amount</td>
    <td>Price: &pound;[PRICE]


    Anyone have any bright ideas? I'm sure I'm missing something, but I can't think what?


  2. #2
    Senior Coder
    Join Date
    Dec 2010
    Thanked 570 Times in 563 Posts
    This is not the code that produces the 3 decimals. Where does the price get inserted into the table? Is this maybe a server side action? Please show the final resulting HTML code without placeholders like [ PRICE ] and please use [ code ] (without the spaces) represented by the # octathorpe icon above the text area when posting code snippets

  3. #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 932 Times in 919 Posts
    document.form.amount.value = x.toFixed(2);
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  4. Users who have thanked felgall for this post:

    Legless (06-12-2014)

  5. #4
    New to the CF scene
    Join Date
    Jun 2014
    Thanked 0 Times in 0 Posts
    Thanks for this, felgall. Yes, that was MY initial thought for curing it too but, for some strange reason, it doesn't affect the final result.

    Back to the drawing board, methinks!


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts