// the X format can only be used with integer number types public void HexFormat() { sampleDisplay = new SampleDisplay(); //TestFormat("0x20E", "X", "020E"); TestFormat(" 0", "X2", "00"); TestFormat(" +0", "X", "0"); TestFormat(" -0", "X", "0"); TestFormat(" 12", "X", "C"); TestFormat(" 12", "X2", "0C"); TestFormat(" 127", "X", "7F"); TestFormat(" 129", "X", "81"); TestFormat(" 128", "X4", "0080"); TestFormat(" 1234", "X", "4D2"); TestFormat(" 1234", "X6", "0004D2"); TestFormat(" -127", "X", "81"); TestFormat(" -128", "X", "80"); TestFormat(" -128", "X4", "80"); TestFormat(" -129", "X", "FF7F"); TestFormat("-1234", "X", "FB2E"); TestFormat("-1234", "X6", "FB2E"); sampleDisplay.WriteOutput(); }
// the G format can be used with all number types public void GeneralFormat() { sampleDisplay = new SampleDisplay(); TestFormat("123", "G", "123"); TestFormat("129", "G", "129"); TestFormat("-129", "G", "-129"); TestFormat("128", "G", "128"); TestFormat("128", "G4", "128"); TestFormat("-128", "G", "-128"); TestFormat("-128", "G2", "-1.3E+02"); TestFormat("1234", "G2", "1.2E+03"); TestFormat("-1234", "G", "-1234"); TestFormat("1234", "G6", "1234"); TestFormat("-1234", "G6", "-1234"); TestFormat("123.78", "G3", "124"); TestFormat("123.7841", "G5", "123.78"); TestFormat("123.7851", "G5", "123.79"); TestFormat("123.78", "G5", "123.78"); TestFormat("123.78", "G4", "123.8"); TestFormat("1234.8999", "G5", "1234.9"); TestFormat("1234.8999", "G6", "1234.9"); TestFormat("1234.8999", "G7", "1234.9"); TestFormat("-1234.901", "G7", "-1234.901"); sampleDisplay.WriteOutput(); }
// the D format can only be used with integers (no double or floats) public void DecimalFormat() { sampleDisplay = new SampleDisplay(); TestFormat(" 123", "D", "123"); TestFormat(" 129", "D", "129"); TestFormat(" -129", "D", "-129"); TestFormat(" 128", "D", "128"); TestFormat(" -128", "D", "-128"); TestFormat(" -128", "D2", "-128"); TestFormat(" 1234", "D2", "1234"); TestFormat("-1234", "D", "-1234"); TestFormat(" 1234", "D6", "001234"); TestFormat("-1234", "D6", "-001234"); sampleDisplay.WriteOutput(); }
// the F format can be used with all number types public void FixedFormat() { sampleDisplay = new SampleDisplay(); TestFormat("123", "F", "123.00"); // default for CultureInvariant is 2 decimal places TestFormat("129", "F", "129.00"); TestFormat("-129", "F", "-129.00"); TestFormat("128", "F", "128.00"); TestFormat("128", "F4", "128.0000"); // bug - int gets different value than float/double TestFormat("-128", "F", "-128.00"); TestFormat("-128", "F2", "-128.00"); TestFormat("1234", "F2", "1234.00"); TestFormat("-1234", "F", "-1234.00"); TestFormat("1234", "F6", "1234.000000"); TestFormat("-1234", "F6", "-1234.000000"); TestFormat("123.78", "F3", "123.780"); TestFormat("123.78", "F1", "123.8"); TestFormat("1234.8999", "F3", "1234.900"); sampleDisplay.WriteOutput(); }
// the N format can be used with all number types public void NumberFormat() { sampleDisplay = new SampleDisplay(); TestFormat("123", "N", "123.00"); // default for CultureInvariant is 2 decimal places TestFormat("129", "N", "129.00"); TestFormat("-129", "N", "-129.00"); TestFormat("128", "N", "128.00"); TestFormat("128", "N4", "128.0000"); TestFormat("-128", "N", "-128.00"); TestFormat("-128", "N2", "-128.00"); TestFormat("1234", "N2", "1,234.00"); TestFormat("-1234", "N", "-1,234.00"); TestFormat("1234", "N6", "1,234.000000"); TestFormat("-1234", "N6", "-1,234.000000"); TestFormat("1234.567", "N2", "1,234.57"); TestFormat("-1234.567", "N2", "-1,234.57"); TestFormat("123456.78", "N2", "123,456.78"); TestFormat("1234567.1210", "N2", "1,234,567.12"); TestFormat("-0.099999999999999978", "N2", "-0.10"); sampleDisplay.WriteOutput(); }