admin管理员组文章数量:1414870
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
4 Answers
Reset to default 3You 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.
本文标签: htmlhow can we make a digit after decimal appear like a superscript in javascriptStack Overflow
版权声明:本文标题:html - how can we make a digit after decimal appear like a superscript in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745204515a2647571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论