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

如何在SAP Crystal Reports中舍入并去除小数位?附公式咨询

SAP Crystal Reports: Rounding to Whole Numbers & Removing Decimals

Hey there! It looks like your two questions are targeting the same core goal—taking numeric values, rounding them to the nearest whole number, and stripping off any decimal places. Let's break this down using your existing formula as a starting point.

Key Concepts to Know

First, SAP Crystal Reports has two straightforward ways to handle this:

  • Using Format Strings: The CStr() function with a format specifier like "0" automatically rounds numbers to the nearest integer and removes decimals when converting to a string.
  • Using the Round() Function: This explicitly rounds a numeric value to a specified number of decimal places (in your case, 0 for whole numbers), which you can then convert to a string.

Adjusting Your Existing Formula

Your current formula is:

WhilePrintingRecords; NumberVar ItemNumber; CStr(ItemNumber, "0") & "/" & CStr(Count({rpt_PackingSlip.LabelQTY}, {rpt_PackingSlip.WorkOrderNo}))

Here are two refined versions that ensure both values are rounded to whole numbers and have decimals removed:

Version 1: Using Format Strings (Simpler)

This leans into the built-in behavior of CStr() to handle rounding and decimal removal in one step, even for the Count() result (in case your aggregation ever returns a non-integer value):

WhilePrintingRecords; 
NumberVar ItemNumber; 
CStr(ItemNumber, "0") & "/" & CStr(Count({rpt_PackingSlip.LabelQTY}, {rpt_PackingSlip.WorkOrderNo}), "0")

Version 2: Using Round() (Explicit & Clear)

If you want to make the rounding logic explicit (great for readability or if you might adjust decimal places later), use the Round() function before converting to a string:

WhilePrintingRecords; 
NumberVar ItemNumber; 
CStr(Round(ItemNumber, 0)) & "/" & CStr(Round(Count({rpt_PackingSlip.LabelQTY}, {rpt_PackingSlip.WorkOrderNo}), 0))

Quick Note

Both methods will round values like 1.4 to 1 and 1.6 to 2, which matches your request to round to the nearest integer while removing decimals. If you ever needed to truncate decimals instead of rounding (e.g., turn 1.9 into 1), you'd use the Int() function—but that's not what you're asking for here.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:22:27