How do I round a number in JSTL?

后端 未结 5 1534
感情败类
感情败类 2020-12-29 02:39

I\'m doing a division in a JSP and I\'d like to round the result - how should I do this?

i.e.



        
5条回答
  •  醉话见心
    2020-12-29 03:25

    What about this dirty hack:

    
    

    But I would do this in a bean and just show the result here. Beside this, you can define functions in your tld or, if that is not supported in your environment get functions in the expression language by implementing a Map and (ab)use it. You implement the get(Object) method to do what you want and call it like this:

    
    

    Note, Helpers provides a "getRound()" method which returns your Map implementation.

提交回复
热议问题