Showing
1 changed file
with
25 additions
and
3 deletions
| @@ -35,13 +35,13 @@ public class LatexFormulaExcelExporterUtil { | @@ -35,13 +35,13 @@ public class LatexFormulaExcelExporterUtil { | ||
| 35 | continue; | 35 | continue; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | - latex.append(comp.getBase().stripTrailingZeros()); | 38 | + latex.append(formatScientificNotation(comp.getBase())); |
| 39 | if (comp.getSup() != null) { | 39 | if (comp.getSup() != null) { |
| 40 | - latex.append("^{+").append(comp.getSup().stripTrailingZeros()).append("}"); | 40 | + latex.append("^{+").append(formatScientificNotation(comp.getSup())).append("}"); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | if (comp.getSub() != null) { | 43 | if (comp.getSub() != null) { |
| 44 | - latex.append("_{-").append(comp.getSub().stripTrailingZeros()).append("}"); | 44 | + latex.append("_{-").append(formatScientificNotation(comp.getSub())).append("}"); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | if (i < componentList.size() - 1) { | 47 | if (i < componentList.size() - 1) { |
| @@ -53,6 +53,28 @@ public class LatexFormulaExcelExporterUtil { | @@ -53,6 +53,28 @@ public class LatexFormulaExcelExporterUtil { | ||
| 53 | return latex.toString(); | 53 | return latex.toString(); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 处理科学计数法表示的大数字 | ||
| 59 | + */ | ||
| 60 | + public static String formatScientificNotation(BigDecimal number) { | ||
| 61 | + if (number == null) return "0"; | ||
| 62 | + | ||
| 63 | + // 对于非常大或非常小的数,stripTrailingZeros()可能会产生科学计数法 | ||
| 64 | + BigDecimal stripped = number.stripTrailingZeros(); | ||
| 65 | + | ||
| 66 | + // 使用toPlainString()确保不使用科学计数法 | ||
| 67 | + String result = stripped.toPlainString(); | ||
| 68 | + | ||
| 69 | + // 如果结果包含"E"(科学计数法),进行特殊处理 | ||
| 70 | + if (result.contains("E")) { | ||
| 71 | + // 转换为普通表示法 | ||
| 72 | + return number.toPlainString(); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + return result; | ||
| 76 | + } | ||
| 77 | + | ||
| 56 | /** | 78 | /** |
| 57 | * 将LaTeX公式字符串渲染为图片字节数组 | 79 | * 将LaTeX公式字符串渲染为图片字节数组 |
| 58 | * | 80 | * |