Crystal xi - string numbers together without decimal places - crystal-reports

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

Related

Concatenate Negative Number and String in SSRS

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.

Crystal Reports 2013: Adding Leading Zeros to Sum in Group Footer

I have a report in Crystal Reports 2013 that is grouping multiple transactions into an aggregate transaction by account number.
The value is Amount, so in the Group Footer is it listed as SumofAmount.
The field must be 17 characters long, so any number must be padded with leading zeros.
The values are assumed to be decimal, so they are all integers.
For example, the following transformations would occur:
3123 needs to be: 00000000000003123
23283792387 needs to be: 00000023283792387
If I right-click in Formula Workshop > Formatting Formulas > Group Footer #1 > SumofAmount I get a New Formatting Formulas which has leading zeros as an option, but how do I define this with a Boolean (this is a requirement)?
Right click on the field you need to have leading zeros.
select format field
select the common tab
select X2 to the right of Display String
Enter the following formula
right("000000000000000"&totext(CurrentFieldValue,"#"),15)
This assumes the total length of the field is 15. To change for your required length
change the number 15 to the desired length of the field
change the number of 0's between the quotes to at least the desired
length of the field
Repeat this for any field you need leading zeros

How can i get 6 digits after comma (matlab)?

I read from text some comma seperated values.
-8.618643,41.141412
-8.639847,41.159826
...
I write script below;
get_in = zeros(lendata,2);
nums = str2num(line); % auto comma seperation.(two points)
for x=1:2
get_in(i,x)=nums(x);
end
it automatically round numbers. For example;
(first row convert to "-8.6186 , 41.1414")
How can i ignore round operation?
I want to get 6 digits after comma.
I tried "str2double" after split line with comma delimeter.
I tried import data tool
But it always rounded to 4 digits, too.
As one of the replies has already said, the values aren't actually rounded, just the displayed values (for ease of reading them). As suggested, if you just enter 'format long' into the command window that should help.
The following link might help with displaying individual values to certain decimal places though: https://uk.mathworks.com/matlabcentral/newsreader/view_thread/118222
It suggests using the sprintf function. For example sprintf(%4.6,data) would display the value of 'data' to 6 decimal places.

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.)

Splitting a string into various combinations

I am in need of some direction on splitting a string into various combinations. Actually my requirement is to split an integer, but I guess those can't be split, that's why I've converted the integer into string.
For eg.
I've a string "123456"
I want to split it like
12 34 56
123 45 6
12 345 6
12 3 456
and like wise. One more problem is, the size of the string can be variable. As I told, these are actually integers, so it can have from 4 places to 7-8 places, and so will be the size of resultant string to be split into combinations.
I currently don't have any code to achieve it. I've just performed the simple splitting operation in the command box, but couldn't think of the way of achieving the required result. Please give me some direction on what I can do.
Thanks.
First you can use the num2str() function to convert the integer value to a string. Once you have converted the number to a string, you can then use the length() function to determine how many digits there are in the number. You can then use the length of the string split up the number in various ways. The example below only splits in groups of two, but you can adjust as desired.
val=123456;
str=num2str(val);
i=1;
k=1;
len=2;%split values into groups of 2
while(i<length(str)-1)
val(k)=str2num(str(i:i+len-1));
i=i+len;
k=k+1;
end
if(i<=length(str))
val(k)=str2num(str(i:end));%catches the remainder
end