开发者

How to have multiple formats in a single text field in jasper reports?

开发者 https://www.devze.com 2023-03-03 05:17 出处:网络
I have a text field that displays 3 parameters with different formats. It has a Date value, a BigDecimal value and a value that has to be dis开发者_如何学Cplayed using percentage display.

I have a text field that displays 3 parameters with different formats. It has a Date value, a BigDecimal value and a value that has to be dis开发者_如何学Cplayed using percentage display.

Can I use a single text field for this or do I have to use one text field for each to have the correct format for each?


You have a few approaches, presuming it is one of the three parameters you want to display in the same location:

  • Use three different fields and a PrintWhenExpression for each parameter.
  • Convert the different fields to a single String variable, with appropriate formatting, and then a single field for that variable value.

The second approach is probably the most applicable for your task. For the conversions, look at:

  • BigDecimal.toString()
  • SimpleDateFormat
  • String.sprintf

See also:

Java: Literal percent sign in printf statement

0

精彩评论

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