Lines 351-361
Link Here
|
351 |
// Excel supports fractions in format strings, which Java doesn't |
351 |
// Excel supports fractions in format strings, which Java doesn't |
352 |
if (!formatStr.contains("-") && |
352 |
if (!formatStr.contains("-") && |
353 |
(formatStr.indexOf("#/#") >= 0 && formatStr.indexOf("#/#") == formatStr.lastIndexOf("#/#")) || |
353 |
(formatStr.indexOf("#/#") >= 0 && formatStr.indexOf("#/#") == formatStr.lastIndexOf("#/#")) || |
354 |
(formatStr.indexOf("?/?") >= 0 && formatStr.indexOf("?/?") == formatStr.lastIndexOf("?/?"))) { |
354 |
(formatStr.indexOf("?/?") >= 0 && formatStr.indexOf("?/?") == formatStr.lastIndexOf("?/?")) || |
|
|
355 |
(formatStr.matches(".*?/[1-9].*") && formatStr.indexOf("?/") == formatStr.lastIndexOf("?/"))) { |
355 |
return new FractionFormat(formatStr); |
356 |
return new FractionFormat(formatStr); |
356 |
} |
357 |
} |
357 |
|
358 |
|
358 |
if (numPattern.matcher(formatStr).find()) { |
359 |
if (numPattern.matcher(formatStr).find()) { |
|
|
360 |
if (formatStr.contains("._")) { |
361 |
if (!formatStr.contains("_._")) { |
362 |
formatStr = formatStr.replace("._", "'.'_"); |
363 |
} |
364 |
} |
365 |
if (formatStr.contains(".\"")) { |
366 |
formatStr = formatStr.replace(".\"", "'.'"); |
367 |
} |
368 |
if (formatStr.contains("\"")) { |
369 |
formatStr = formatStr.replace("\"", ""); |
370 |
} |
371 |
if (formatStr.endsWith(".")) { |
372 |
if (!formatStr.endsWith("_.")) { |
373 |
formatStr = formatStr.substring(0, formatStr.length() - 1) + "'.'"; |
374 |
if (formatStr.contains(".;")) { |
375 |
formatStr = formatStr.replace(".;", "'.';"); |
376 |
} |
377 |
} |
378 |
} |
359 |
return createNumberFormat(formatStr, cellValue); |
379 |
return createNumberFormat(formatStr, cellValue); |
360 |
} |
380 |
} |
361 |
|
381 |
|
Lines 700-705
Link Here
|
700 |
if (result.contains("E") && !result.contains("E-")) { |
720 |
if (result.contains("E") && !result.contains("E-")) { |
701 |
result = result.replaceFirst("E", "E+"); |
721 |
result = result.replaceFirst("E", "E+"); |
702 |
} |
722 |
} |
|
|
723 |
if (result.charAt(0) == '*') { |
724 |
result = result.substring(1); |
725 |
} |
703 |
return result; |
726 |
return result; |
704 |
} |
727 |
} |
705 |
|
728 |
|
Lines 981-988
Link Here
|
981 |
} |
1004 |
} |
982 |
|
1005 |
|
983 |
public String format(Number num) { |
1006 |
public String format(Number num) { |
984 |
double wholePart = Math.floor(num.doubleValue()); |
1007 |
double wholePart; |
985 |
double decPart = num.doubleValue() - wholePart; |
1008 |
double decPart; |
|
|
1009 |
if (num.doubleValue() >= 0) { |
1010 |
wholePart = Math.floor(num.doubleValue()); |
1011 |
decPart = num.doubleValue() - wholePart; |
1012 |
} else { |
1013 |
wholePart = Math.ceil(num.doubleValue()); |
1014 |
decPart = wholePart - num.doubleValue(); |
1015 |
} |
986 |
if (wholePart + decPart == 0) { |
1016 |
if (wholePart + decPart == 0) { |
987 |
return "0"; |
1017 |
return "0"; |
988 |
} |
1018 |
} |
Lines 1014-1023
Link Here
|
1014 |
} |
1044 |
} |
1015 |
} |
1045 |
} |
1016 |
} |
1046 |
} |
|
|
1047 |
|
1017 |
NumberFormat neumFormatter = new DecimalFormat(fractParts[0]); |
1048 |
NumberFormat neumFormatter = new DecimalFormat(fractParts[0]); |
|
|
1049 |
NumberFormat wholeFormatter; |
1050 |
if (!fractParts[1].contains("#")) { |
1051 |
wholeFormatter = new DecimalFormat(parts[0]); |
1052 |
currNeum = Math.round(decPart * Integer.parseInt(fractParts[1])); |
1053 |
String result = wholeFormatter.format(wholePart) + " " + neumFormatter.format(currNeum) + "/" + fractParts[1]; |
1054 |
return result; |
1055 |
} |
1056 |
|
1018 |
NumberFormat denomFormatter = new DecimalFormat(fractParts[1]); |
1057 |
NumberFormat denomFormatter = new DecimalFormat(fractParts[1]); |
1019 |
if (parts.length == 2) { |
1058 |
if (parts.length == 2) { |
1020 |
NumberFormat wholeFormatter = new DecimalFormat(parts[0]); |
1059 |
wholeFormatter = new DecimalFormat(parts[0]); |
1021 |
String result = wholeFormatter.format(wholePart) + " " + neumFormatter.format(currNeum) + "/" + denomFormatter.format(currDenom); |
1060 |
String result = wholeFormatter.format(wholePart) + " " + neumFormatter.format(currNeum) + "/" + denomFormatter.format(currDenom); |
1022 |
return result; |
1061 |
return result; |
1023 |
} else { |
1062 |
} else { |