Converting values to unit prefixes in JSP page

后端 未结 3 1049
迷失自我
迷失自我 2021-01-14 06:39

How can I convert values to to other units in JSP page. For example if I get value 1001 and I want to only display 1K, or when I get 1 000 001 I would like to display 1M and

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-14 07:19

    Maybe you could write a custom implementation of java.text.Format or override java.text.NumberFormat to do it. I'm not aware of an API class that does such a thing for you.

    Or you could leave that logic in the class that serves up the data and send it down with the appropriate format. That might be better, because the JSP should only care about formatting issues. The decision to display as "1000" or "1K" could be a server-side rule.

提交回复
热议问题