当前位置: 首页>>代码示例>>Java>>正文


Java FmtNumber类代码示例

本文整理汇总了Java中org.supercsv.cellprocessor.FmtNumber的典型用法代码示例。如果您正苦于以下问题:Java FmtNumber类的具体用法?Java FmtNumber怎么用?Java FmtNumber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FmtNumber类属于org.supercsv.cellprocessor包,在下文中一共展示了FmtNumber类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testConvertsToBasicObjects

import org.supercsv.cellprocessor.FmtNumber; //导入依赖的package包/类
@Test
public void testConvertsToBasicObjects() throws IOException {
	Calendar calendar = Calendar.getInstance();
	calendar.set(Calendar.YEAR, 1999);
	calendar.set(Calendar.MONTH, 6);
	calendar.set(Calendar.DAY_OF_MONTH, 12);
	
	FeatureBean character = new FeatureBean("John", "Connor", 16);
	character.setSavings(new BigDecimal(6.65));
	character.setBirthDate(calendar.getTime());
	
	String[] mapping = { "lastName", "firstName", "age", "birthDate", "savings" };
	DecimalFormat formatter = new DecimalFormat();
	formatter.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance());
	CellProcessor[] processors = { new NotNull(), new NotNull(), new NotNull(), new FmtDate("yyyy-MM-dd"),
		new FmtNumber(formatter) };
	
	StringWriter writer = new StringWriter();
	CsvPreference customPreference = new Builder('"', '|', "\r\n").build();
	CsvBeanWriter beanWriter = new CsvBeanWriter(writer, customPreference);
	beanWriter.write(character, mapping, processors);
	beanWriter.close();
	
	String csv = writer.toString();
	Assert.assertNotNull(csv);
	Assert.assertEquals("Connor|John|16|1999-07-12|" + formatter.format(character.getSavings()) + "\r\n", csv);
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:28,代码来源:WritingFeaturesTest.java

示例2: testConverterSupport

import org.supercsv.cellprocessor.FmtNumber; //导入依赖的package包/类
@Test
public void testConverterSupport() throws IOException {
	Calendar calendar = Calendar.getInstance();
	calendar.set(Calendar.YEAR, 1999);
	calendar.set(Calendar.MONTH, 6);
	calendar.set(Calendar.DAY_OF_MONTH, 12);
	
	FeatureBean character = new FeatureBean("John", "Connor", 16);
	character.setSavings(new BigDecimal(6.65));
	character.setBirthDate(calendar.getTime());
	
	String[] mapping = { "lastName", "firstName", "age", "birthDate", "savings" };
	DecimalFormat formatter = new DecimalFormat();
	formatter.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance());
	CellProcessor[] processors = { new NotNull(), new NotNull(), new NotNull(), new FmtDate("yyyy-MM-dd"),
		new FmtNumber(formatter) };
	
	StringWriter writer = new StringWriter();
	CsvPreference customPreference = new Builder('"', '|', "\r\n").build();
	CsvBeanWriter beanWriter = new CsvBeanWriter(writer, customPreference);
	beanWriter.write(character, mapping, processors);
	beanWriter.close();
	
	String csv = writer.toString();
	Assert.assertNotNull(csv);
	Assert.assertEquals("Connor|John|16|1999-07-12|" + formatter.format(character.getSavings()) + "\r\n", csv);
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:28,代码来源:WritingFeaturesTest.java

示例3: buildForWriting

import org.supercsv.cellprocessor.FmtNumber; //导入依赖的package包/类
@Override
public Optional<CellProcessor> buildForWriting(final Class<Integer> type, final FieldAccessor field,
        final Configuration config, final Class<?>[] groups) {
    
    CellProcessor processor = new NotNull(new FmtNumber(new DecimalFormat("#,##0")));
    return Optional.of(processor);
}
 
开发者ID:mygreen,项目名称:super-csv-annotation,代码行数:8,代码来源:ProcesssorBuilderTest.java


注:本文中的org.supercsv.cellprocessor.FmtNumber类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。