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