开发者

Setting default fmt formatNumber maxFractionDigits for all jsp pages

Is it possible to have the following tag always display 5 decimal places?

<fmt:formatNumber type="currency" value="${number}" />

wi开发者_如何学运维thout having to change it to

<fmt:formatNumber type="currency" maxFractionDigits="5" value="${number}" />

basically I have so many of these and I want them all to change, I want 5 decimal places to be the default.


Yes. You cam implement this by extending fmt:formatNumber functionality.

For this, create a class extending org.apache.taglibs.standard.tag.rt.fmt.FormatNumberTag to set maxFractionDigits to 5 by default (when not supplied).

You would also need to change the reference in your fmt tag library descriptor (tld) file to point to your own implementation.

These should be present in your jstl jar located in WEB-INF\lib by default .

EDIT: Personally, I would go for Adeel's approach of setting up a custom locale, if at all possible.


Direct answer is No, if its of less effort then you can set 5 decimal value only in number at servlet


You might be able to set a custom Locale, which does nothing but override double formatting, for the application. In this way you just need to do it in one place.


That's not possible, no. But you can install/use a text editor which has kind of a Find And Replace In All Files function. Editplus for example. I believe Notepad++ is also able to.

Assuming Editplus, just open all JSP files in the editor. Hit Ctrl+H. Fill in the following

Find what: <fmt:formatNumber type="currency" value
Replace with: <fmt:formatNumber type="currency" maxFractionDigits="5" value

Click the All open files option in Replace all range and then click Replace All.

Setting default fmt formatNumber maxFractionDigits for all jsp pages

That's it.

Choose File > Save All to save them all. Press if necessary F5 to refresh your Eclipse/Netbeans/whatever project to refresh the files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜