问题描述
在桌面Java项目中,我使用StandardXYToolTipGenerator
在图表上生成工具提示.
In desktop Java project I used StandardXYToolTipGenerator
for generating tooltips on chart.
渲染器的配置如下:
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} - {2} ({1})",new SimpleDateFormat("HH:mm:ss"), NumberFormat.getNumberInstance()));
其中{2}
是值(示例1.149431),但是当我使用NumberFormat
时,它会自行格式化并返回值1.149,我想精确取整.如何获得?有什么主意吗?
Where {2}
is value (example 1.149431) but when I am using NumberFormat
it format itself and return value 1.149, I want get precisely rounding. How to get it? Any idea?
我尝试扩展NumberFormat
类,但是方法format(double number)
是最终的...
I tried extend NumberFormat
class, but method format(double number)
is final...
推荐答案
NumberFormat.getNumberInstance()
"返回当前默认FORMAT
语言环境的通用数字格式.您可以根据需要调整舍入模式和位数.根据此示例,下面的片段保留了默认的舍入模式并指定了五个数字.
NumberFormat.getNumberInstance()
"Returns a general-purpose number format for the current default FORMAT
locale." You can adjust the rounding mode and the number of digits as desired. Based on this example, the fragment below retains the default rounding mode and specifies five digits.
NumberFormat format = NumberFormat.getNumberInstance();
format.setMinimumFractionDigits(5);
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(
"{2}", DateFormat.getDateInstance(), format));
顺便说一句,请确认您选择的SimpleDateFormat
是否适合您的目标语言环境.
As an aside, verify that your chosen SimpleDateFormat
is appropriate for for your target locale.
这篇关于使用StandardXYToolTipGenerator格式化工具提示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!