You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome在线PDF表单计算异常问题求助

Fixing Calculation Errors in Finnish PDF Travel Expense Forms for Chrome

I’ve dealt with this exact quirk before—Chrome’s built-in PDF handler doesn’t properly recognize comma-based decimal separators like Finnish uses, which is why your calculations work flawlessly in Acrobat DC but break in Chrome. Let’s break down the issues and fix them step by step:

Problem Breakdown

  • Sum calculation fields (like the total including "Taksi"): Chrome parses comma-separated values like 20,50 as the integer 20050 (it strips the comma entirely instead of treating it as a decimal separator), leading to that absurdly high total.
  • "Kilometrikorvaus" custom calculation: When you input 0,44, JavaScript (which Chrome uses for PDF form logic) can’t parse the comma as a decimal. parseFloat("0,44") returns NaN, so multiplying by anything results in NaN—hence the nan € display.

Fix 1: Repair Sum Calculation Fields

Ditch the default "Sum of fields" setting (which Chrome mishandles) and use a custom JavaScript calculation that explicitly converts comma-separated strings to valid numbers:

  1. Open the PDF in Acrobat DC (you can’t edit form calculations in Chrome).
  2. Locate your total calculation field, open its Properties > Calculate tab.
  3. Select "Custom calculation script" and replace any existing code with this (update the expenseFields array to match your actual field IDs):
    // List all fields you need to sum (replace with your form's actual field names)
    var expenseFields = ["taksi", "hotelli", "ruoka", "km1_total"];
    var total = 0;
    
    expenseFields.forEach(function(fieldName) {
        var fieldValue = this.getField(fieldName).valueAsString;
        // Convert comma-separated string to a JavaScript-compatible number
        var numericValue = parseFloat(fieldValue.replace(",", ".")) || 0;
        total += numericValue;
    });
    
    // Convert total back to Finnish format with comma separator and euro symbol
    event.value = total.toFixed(2).replace(".", ",") + " €";
    
  4. Save the PDF and test in Chrome—inputting 20,50 in "Taksi" should now show the correct total.

Fix 2: Fix Custom Kilometer Calculation

Your existing script doesn’t account for comma separators. Update the script for the "Kilometrikorvaus" calculation field to:

var kmField = this.getField("km1");
var rateField = this.getField("a5");

// Convert field values to valid numbers (handle Finnish comma separators)
var kmValue = parseFloat(kmField.valueAsString.replace(",", ".")) || 0;
var rateValue = parseFloat(rateField.valueAsString.replace(",", ".")) || 0;

if (kmValue * rateValue !== 0) {
   var result = kmValue * rateValue;
   // Format result back to Finnish decimal format for display
   event.value = result.toFixed(2).replace(".", ",");
} else {
   event.value = "";
}

Key Changes Explained:

  • valueAsString ensures we get the raw input string (e.g., "0,44" instead of a corrupted numeric value).
  • replace(",", ".") converts the string to a format JavaScript can parse as a decimal.
  • || 0 handles empty fields or invalid inputs, preventing NaN errors.
  • toFixed(2).replace(".", ",") converts the calculated number back to the Finnish comma-separated format for proper display.

Testing Tips

After making changes, verify these scenarios in Chrome:

  • Input 20,50 in "Taksi" → total should show 20,50 € (if it’s the only expense).
  • Input 2 in the km field and 0,44 in the rate field → calculation should show 0,88 €.
  • Test empty fields to ensure they don’t break the total (should default to 0).

内容的提问来源于stack exchange,提问作者Squrppi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:46:51