Concatenate Negative Number and String in SSRS - ssrs-2008

I'm having a trouble in concatenating the Negative numbers and Strings. I've successfully display the negative numbers with parenthesis (ex. (3)) but when I add the string to it the format of number becomes -3 again. This is my expression:
=Cint(Fields!UNT_TAKEN.Value) & " UNITS"
It returns me with this value -3 UNITS
But I want to return (3) UNITS
Thank you in advance.

If UNIT_TAKEN is already a number then you can just set the format property of the cell/textbox to
0 Units;(0) Units
If UNIT_TAKEN is a string then set the value expression of the cell/textbox to
=FORMAT(CINT(Fields!UNIT_TAKEN.Value),"0 Units;(0) Units")
Below I created a dataset with both a numeric and string version of seven numbers. The table below shows the actual values and the formatted values as above.

Related

Remove commas and decimal places from number field

I am trying to add two zero place holders in front of a field without changing the actual values involved. The field is an order number that is being pulled from MOMs. So right now that fields' formula is {cms.ORDERNO}.
When I try '00'+{cms.ORDERNO} the field displays 001,254.00. How can I remove the decimals and comma so it displays 001254?
The usual trick is to pad with plenty of extra digits on the left and then only take the six you really want from the right. This would handle any order number ranging from 1 to 999999.
right("000000" + totext({cms.ORDERNO}, "0"), 6)
When you don't specify a format string, as you tried, it uses default settings which usually come from Windows. By the way, if I recall correctly cstr() and totext() are equivalent for the most part but totext() has more options.
You should also be able to specify "000000" as the format string to produce the left-padded zeroes. Sadly I don't have Crystal Reports installed or I'd check it out for you to be sure. If this is the case then you probably don't need a formula if you just want to use the formatting options for the field on the canvas. If you do use a formula it's still simple.
totext({cms.ORDERNO}, "000000")
You definitely want to use the Replace formula a few times for this. The formula below converts ORDERNO into string, removes any commas and trailing decimal places, then adds the two zeroes at the beginning:
`00` + REPLACE(REPLACE(CSTR({cms.ORDERNO}),".00",""),",","")
So for example, if cms.ORDERNO is 1,254.00 the output from this formula would be 001254
I know this is older, but better solutions exists and I ran across this same issue. ToText has what you need built right in.
"00" + ToText({cms.ORDERNO}, 0, "")
From the Crystal Documentation:
ToText (x, y, z)
x is a Number or Currency value to be converted into a text string; it
can be a whole or fractional value.
y is a whole number indicating the number of decimal places to carry
the value in x to (This argument is optional.).
z is a single character text string indicating the character to be
used to separate thousands in x. Default is the character specified in
your International or Regional settings control panel. (This argument
is optional.)

How can I set a format for each column when displaying my table?

My table only contains numerical data. I have format set to long and all of the variables are of that type. How can tell MATLAB to display each column differently? i.e column 1 as type long with 15 decimal digit precision, column 2 in scientific notation with 4 decimal precision, etc?

Crystal xi - string numbers together without decimal places

I need to build a text field by stringing 2 numbers together for a barcode.
For example: fld1 is 12345678 and fld2 is 145.99.
fld1 needs to be 9 characters long, zero filled and fld2 needs to be 8 characters long, zero filled.
I need the string to be 01234567800014599
There is 2 step to do. One need concatenation, for this '+' is used to concatenate.
For the leading zero you can use Right function (refer below link)
ToText({table1.fld1},"000000000") + ToText({table1.fld1},"000000000")
or
Right("0000"&{table1.fld2},8) + Right("0000"&{table1.fld2},8)
just check this link :- Padding a fixed number with leading zeros up to a fixed length
Crystal report; Combining rows of data into a single value

SSRS graph with optional decimal positions

Is is possible to show optional decimal numbers for the values in the graph? I want to show up to 2 decimal values but only if the user inputs them. If the value is 9.34, I want it to show that. But if the value is just 9, I want it to show just 9. If the users types 9.3 then only that should be shown.
You can accomplish that by converting the decimal value to a string and then using format characters like this:
=Format(CStr(Fields!a.Value),"#.##");
The # character will only diplay if a decimal value exists. ( fyi, if you wanted the opposite from the format string, using 0.00 would force display zero's even if the values were integers ).
You can also use a combination such as 0.## or 0#.##
Further:
You can also just place that format string in the Custom option under Number in properties.

Crystal Reports Formula: Getting the decimal and non-decimal part

For example I have a value of 103.33 I want to put 100 to one variable and 33 to another variable. How can I do this?
Thanks.
Create two formula fields, eg wholepart and decimalpart.
The formula for wholepart is trunc({yourfieldnamehere}) and the formula for decimalpart is {yourfieldnamehere} - trunc({yourfieldnamehere})
The value you get in decimalpart is going to be the decimal fraction; if you know it's always going to be a 2 digit decimal, multiply by 100. If it's variable, you could do a quick string conversion, count the digits and multiply by the appropriate power of 10.
Hampk
Use trunc to get Integer portion and then subtract to get decimal portion. Convert decimal portion to text by ToText and then take Split function to get after "." from decimal portion
or
Use ToText and use Split function to get after and before "."
You can also use the 'Remainder' function to find the number after the decimal point. For example, REMAINDER ({FIELD NAME},1) should give you 0.33