Need currency pound symbol before amount

Joined
Feb 25, 2022
Messages
19
Reaction score
1
I need to display a pound currency symbol before the amount that is calculated

Below is the code I currently have

Code:
<th class="text-right py-1 px-2 grand-total">0</th>

function calc(){
        var grand_total = 0;
        $('table#list tbody input[name="total[]"]').each(function(){
            grand_total += parseFloat($(this).val())
            
        })
      
        $('table#list tfoot .grand-total').text(parseFloat(grand_total).toLocaleString('en-gb', {style:'decimal',maximumFractionDigit:2}))
        $('[name="amount"]').val(parseFloat(grand_total))

    }

I'm not sure where to add it within that code, can anyone help please
 
Joined
Feb 3, 2025
Messages
12
Reaction score
1
You can use the £ symbol before the amount like this:

  • £50
  • £1,000
  • £3.99

If you're working in a document or code, let me know where you need it, and I can help format it correctly!
 
Joined
Jul 4, 2023
Messages
583
Reaction score
78
JavaScript:
function calc() {
  let grand_total = 0;
  $('table#list tbody input[name="total[]"]').each(function() {
    grand_total += parseFloat($(this).val()) || 0; // Ensuring NaN is handled
  });

  // Format the number with GBP currency symbol
  var formatted_total = '£' + grand_total.toLocaleString('en-GB', {
    style: 'decimal',
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
  });

  // Update the total display
  $('table#list tfoot .grand-total').text(formatted_total);
}
  • Added '£' + before the formatted total to ensure the currency symbol is displayed.
  • Used minimumFractionDigits: 2 to ensure two decimal places (e.g., £10.00 instead of £10).
  • Fixed .maximumFractionDigit typo → It should be maximumFractionDigits instead.
  • Handled NaN cases → Used || 0 in case parseFloat($(this).val()) returns NaN.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,300
Messages
2,571,537
Members
48,327
Latest member
GWEDalene9
Top