html - how can we make a digit after decimal appear like a superscript in javascript? - Stack Overflow

how can we make a digit after decimal appear like a superscript in java. here is the example I have the

how can we make a digit after decimal appear like a superscript in java.

here is the example

I have the price say suppose $14.98, is there a way that i can print those .98 as supercript.

thank you

this is how i am getting price value <%=price.getBasePrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString()%>

how can we make a digit after decimal appear like a superscript in java.

here is the example

I have the price say suppose $14.98, is there a way that i can print those .98 as supercript.

thank you

this is how i am getting price value <%=price.getBasePrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString()%>

Share Improve this question edited Oct 4, 2011 at 17:11 nyshangal asked Oct 4, 2011 at 16:51 nyshangalnyshangal 1022 silver badges8 bronze badges 6
  • 2 Where/how are you outputting that value? In the console? In a Swing application? In HTML from a JSP? – Freiheit Commented Oct 4, 2011 at 16:52
  • 4 java or javascript? big difference.... – Jason S Commented Oct 4, 2011 at 16:52
  • 2 FYI, JavaScript is not a portmanteau of Java and superscript. – BoltClock Commented Oct 4, 2011 at 16:53
  • Like a price, or as a superscript? Superscripts are smaller, but easier. – Ed Staub Commented Oct 4, 2011 at 16:58
  • OK, that looks like Java + server-side script rather than Javascript. @user968951: in the future, please don't edit the OP's tags w/o getting the OP to clarify. – Jason S Commented Oct 4, 2011 at 17:25
 |  Show 1 more ment

4 Answers 4

Reset to default 3

You can superscript in Javascript by using the .sup() function:

<script>
var j = "14.98";
j = j.split(".");

document.write("$" + j[0] + j[1].sup());
</script>

Which Prints: $1498

$('.price').each(function () {
    var $this = $(this),
        $val = $this.text(),
        dec_pos = $val.indexOf('.');
    $this.html($val.substring(0, dec_pos) + '<sup>' + $val.substring(dec_pos + 1) + '</sup>');
});

http://jsfiddle/tD9PW/

If you want to output to an HTML page (and I assume you do if you mention Javascript), there is a tag <sup> that would do the job:

<span>14.<sup>98</sup></span>

It's pure HTML, not Javascript, but you can use Javascript to generate this HTML.

You do NOT need to use the decimal point when the cents are superscripted. This is particularly true when the type size is very large on posters or billboards.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745204516a4616525.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信