Formatting a field using ToText in a Crystal Reports formula field - crystal-reports

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.
I tried format strings like '###.00;(###.00)' and '(###.00)' but these were rejected as invalid. How can I achieve my goal?

I think you are looking for ToText(CCur(#Price}/{ValuationReport.YestPrice}*100-100))
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,
Replace (ToText(CCur({field})),"$" , "") that will give the parentheses for negative numbers
It is a little hacky, but I'm not sure CR is very kind in the ways of formatting

if(isnull({uspRptMonthlyGasRevenueByGas;1.YearTotal})) = true then
"nd"
else
totext({uspRptMonthlyGasRevenueByGas;1.YearTotal},'###.00')
The above logic should be what you are looking for.

Related

How do I remove the actual decimal from a numeric field that I'm converting to text? ex: 125.02 needs to be 12502

I'm creating an OCR line for our remits that our scanner will read. The scanner doesn't allow the '.' in the field - it assumes the last 2 digits are the decimal place values. I'm converting the field to to text but not sure how to remove the '.' and keep the decimal place values.
The most simple solution would be to create a Formula Field and use the Replace() function. The formula for your Formula Field would look like this:
StringVar myVariable;
myVariable := Replace({table.column}, ".", "");
myVariable;
This will search {table.column} for the first occurrence of a decimal and replace it with an empty string.
However, if your intent is to barcode the value, there may be a UFL available that could also do this for you. When creating barcodes, User Function Libraries are usually preferred because they have functions specifically designed to encode your barcode values. They aren't required though and you can always choose to manually encode barcode values manually with Formula Fields.

Crystal Reports formatting values by parameter

I have a formula which shows the decimal points
IF {?ShowDecimals} = "Y"
then
Round ({?Box1CY},2 )
Round ({?Box2CY},2 )
Box1CY and Box2CY are my text fields;
ShowDecimals = "Y" or "N"
I want to toggle decimal points. Could you help me to do that?
You cannot control the display formatting of one parameter using the value of another parameter (unless you wish to write your own Crystal Reports viewer application).
Looks like Box1CY and Box2CY are parameters rather than "text fields".
Regardless, your expression is missing the 'THEN'.
It would be easier to help if you provide more details.

How do I format numeric string value to 2 decimal places in Crystal Reports 2008?

I am having trouble formatting field DetUnitPrice which is a string value to 2 decimal places. It is currently showing 4 decimal places and I need it to display 2 decimal places. I am trying to do this using Crystal Reports 2008. Can someone help?
Thanks
Dom
When you convert a number to text using the totext() function and handle the decimals.
totext({number_field}, 3)
112,158
Totext({EnforcmentOrdersTemplate.TotalPaid},3)
If it's actually a string value you need to convert to a number:
CDbl("102.1234")
You can then set the format to have 2 decimal places.
If you want it to stay as text you can convert back to text:
CStr(CDbl("102.1234"), 2)
The ToText() function accepts arguments that control number of decimals and thousand separator. In the solution below, I don't specify the thousand separator argument, so it would be set to the default:
ToText(Val({DetUnitPrice}), 2)

zip code + 4 mail merge treated like an arithmetic expression

I'm trying to do a simple mail merge in Word 2010 but when I insert an excel field that's supposed to represent a zip code from Connecticut (ie. 06880) I am having 2 problems:
the leading zero gets suppressed such as 06880 becoming 6880 instead. I know that I can at least toggle field code to make it so it works as {MERGEFIELD ZipCode # 00000} and that at least works.
but here's the real problem I can't seem to figure out:
A zip+4 field such as 06470-5530 gets treated like an arithmetic expression. 6470 - 5530 = 940 so by using above formula instead it becomes 00940 which is wrong.
Perhaps is there something in my excel spreadsheet or an option in Word that I need to set to make this properly work? Please advise, thanks.
See macropod's post in this conversation
As long as the ZIP codes are reaching Word (with or without "-" signs in the 5+4 format ZIPs, his field code should sort things out. However, if you are mixing text and numeric formats in your Excel column, there is a danger that the OLE DB provider or ODBC driver - if that is what you are using to get the data - will treat the column as numeric and return all the text values as 0.
Yes, Word sometimes treats text strings as numeric expressions as you have noticed. It will do that when you try to apply a numeric format, or when you try to do a calculation in an { = } field, when you sum table cell contents in an { = } field, or when Word decides to do a numeric comparison in (say) an { IF } field - in the latter case you can get Word to treat the expression as a string by surrounding the comparands by double-quotes.
in Excel, to force the string data type when entering data that looks like a number, a date, a fraction etc. but is not numeric (zip, phone number, etc.) simply type an apostrophe before the data.
=06470 will be interpreted as a the number 6470 but ='06470 will be the string "06470"
The simplest fix I've found is to save the Excel file as CSV. Word takes it all at face value then.

Data field formatting

I am trying to format a number field to display in this particular way 0001234,
i can do it in VB using the Format(right command, but crystal basic doesn't recognise 'Format'
This Crystal formula will add 0s to the left of the number until it is 7 digits long. The cstr() is there to get rid of the decimal and the characters to the right of the decimal:
Right("0000000"&
cstr({Field},0,"")
,7)
I recommend putting this formula in the display string of your field.