问题描述
我正在尝试创建一个 Crystal Reports 公式字段(用于计算价格的百分比变化),如果特定的报告字段为空,它将返回N/A",但使用会计将数字返回到小数点后两位如果不是,则格式化(用括号括起来的负数).
I'm trying to create a Crystal Reports formula field (to calculate the percentage change in a price) that will return "N/A" if a particular report field is null, but return a number to two decimal places using accounting format (negative numbers surrounded by parentheses) if it is not.
我能做到的最接近的是:
The closest I have been able to manage is this:
If IsNull({ValuationReport.YestPrice}) Then
'N/A'
Else
ToText({@Price}/{ValuationReport.YestPrice}*100-100, '###.00', 2)
但是,这表示使用负号而不是括号的负数.
However this represents negative numbers using a negative sign, not parentheses.
我尝试了像 '###.00;(###.00)' 和 '(###.00)' 这样的格式字符串,但这些字符串被视为无效而被拒绝.我怎样才能实现我的目标?
I tried format strings like '###.00;(###.00)' and '(###.00)' but these were rejected as invalid. How can I achieve my goal?
推荐答案
我想你在找 ToText(CCur(@Price}/{ValuationReport.YestPrice}*100-100))
您可以使用 CCur
将数字或字符串转换为货币格式.CCur(number)
或 CCur(string)
You can use CCur
to convert numbers or string to Curency formats. CCur(number)
or CCur(string)
我想这可能就是你要找的,
I think this may be what you are looking for,
替换 (ToText(CCur({field})),"$" , "")
这将为负数提供括号
这有点hacky,但我不确定CR在格式化方式上是否非常友好
It is a little hacky, but I'm not sure CR is very kind in the ways of formatting
这篇关于在 Crystal Reports 公式字段中使用 ToText 格式化字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!