Lines 660-663
public class TestDataFormatter {
Link Here
|
660 |
assertTrue(DateUtil.isADateFormat(-1, "dd/mm/yy;[red]dd/mm/yy")); |
660 |
assertTrue(DateUtil.isADateFormat(-1, "dd/mm/yy;[red]dd/mm/yy")); |
661 |
assertTrue(DateUtil.isADateFormat(-1, "[h]")); |
661 |
assertTrue(DateUtil.isADateFormat(-1, "[h]")); |
662 |
} |
662 |
} |
|
|
663 |
|
664 |
@Test |
665 |
public void testLargeNumbersAndENotation() throws IOException{ |
666 |
assertFormatsTo("1E+86", 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999d); |
667 |
assertFormatsTo("1E-84", 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000001d); |
668 |
// Smallest double |
669 |
assertFormatsTo("1E-323", 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001d); |
670 |
|
671 |
// "up to 11 numeric characters, with the decimal point counting as a numeric character" |
672 |
// https://support.microsoft.com/en-us/kb/65903 |
673 |
assertFormatsTo( "12345678911", 12345678911d); |
674 |
assertFormatsTo( "1.23457E+11", 123456789112d); // 12th digit of integer -> scientific |
675 |
assertFormatsTo( "-12345678911", -12345678911d); |
676 |
assertFormatsTo( "-1.23457E+11", -123456789112d); |
677 |
assertFormatsTo( "0.1", 0.1); |
678 |
assertFormatsTo( "0.000000001", 0.000000001); |
679 |
assertFormatsTo( "1E-10", 0.0000000001); // 12th digit |
680 |
assertFormatsTo( "-0.000000001", -0.000000001); |
681 |
assertFormatsTo( "-1E-10", -0.0000000001); |
682 |
assertFormatsTo( "123.4567892", 123.45678919); // excess decimals are simply rounded away |
683 |
assertFormatsTo("-123.4567892", -123.45678919); |
684 |
assertFormatsTo( "1.234567893", 1.2345678925); // rounding mode is half-up |
685 |
assertFormatsTo("-1.234567893", -1.2345678925); |
686 |
assertFormatsTo( "1.23457E+19", 12345650000000000000d); |
687 |
assertFormatsTo("-1.23457E+19", -12345650000000000000d); |
688 |
assertFormatsTo( "1.23457E-19", 0.0000000000000000001234565d); |
689 |
assertFormatsTo("-1.23457E-19", -0.0000000000000000001234565d); |
690 |
assertFormatsTo( "1.000000001", 1.000000001); |
691 |
assertFormatsTo( "1", 1.0000000001); |
692 |
assertFormatsTo( "1234.567891", 1234.567891123456789d); |
693 |
assertFormatsTo( "1234567.891", 1234567.891123456789d); |
694 |
assertFormatsTo( "12345678912", 12345678911.63456789d); // integer portion uses all 11 digits |
695 |
assertFormatsTo( "12345678913", 12345678912.5d); // half-up here too |
696 |
assertFormatsTo("-12345678913", -12345678912.5d); |
697 |
assertFormatsTo( "1.23457E+11", 123456789112.3456789d); |
698 |
} |
699 |
|
700 |
private static void assertFormatsTo(String expected, double input) throws IOException { |
701 |
Workbook wb = new HSSFWorkbook(); |
702 |
try { |
703 |
Sheet s1 = wb.createSheet(); |
704 |
Row row = s1.createRow(0); |
705 |
Cell rawValue = row.createCell(0); |
706 |
rawValue.setCellValue(input); |
707 |
CellStyle newStyle = wb.createCellStyle(); |
708 |
DataFormat dataFormat = wb.createDataFormat(); |
709 |
newStyle.setDataFormat(dataFormat.getFormat("General")); |
710 |
String actual = new DataFormatter().formatCellValue(rawValue); |
711 |
assertEquals(expected, actual); |
712 |
} |
713 |
finally { |
714 |
wb.close(); |
715 |
} |
716 |
} |
663 |
} |
717 |
} |
664 |
- |
|
|