user1019053
user1019053

Reputation: 61

Format price using javascript (preferably jQuery)

I am working on a site that is outputting price like so: KD45.000 What I would like to do is show the KD and the 3 zeros after the decimal point at half the height of the 45. Thanks Adam

Upvotes: 2

Views: 410

Answers (3)

Caleb Gray
Caleb Gray

Reputation: 3097

This should be a complete solution for what you're trying to do:

function FormatPrice(price) {
  price = price.split('.');
  return '<sub>' + (price[0] || 0) + '</sub>.' + (price[1] || '000');
}

Originally: KD45.000

FormatPrice('45.000'): KD45.000

Upvotes: 0

Blender
Blender

Reputation: 298196

Split the string using .split('.') into two parts. Output the segments like so:

<sup>KD</sup>{segment1}<sup>.{segment2}</sup>

Upvotes: 1

Manuel van Rijn
Manuel van Rijn

Reputation: 10305

no javascript just html

KD45.000

Code:

 <sup>KD</sup>45<sup>.000</sup>

Upvotes: 2

Related Questions