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

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

Related

Convert decimal point number to integer - PowerShell

I am writing a PowerShell script that converts a number with a decimal point into an integer.
$val = 1024.24
How to convert this value to integer? (I want it to be 1024)
Use floor rounding, which rounds to the lower whole number
[Math]::Floor($val)
Edit: if just discarding decimal part is not what you are looking for you can use [Math]::Round($val) which will round the number like normal math rounding or you can use [Math]::Ceiling($val) which will round up (in your case it will round to 1025) and it is probably not what you need but it is good to know that you have these options as well.

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.

printf number format for constant width lat/long in exiftool

Apparently I am misunderstanding the printf man page. (Or else it's a bug in exiftool 10.55 and 10.77)
I am trying to get GPS coordinates from image files with exiftool. I would like to make them the same width and without unnecessary spaces.
The format string I tried, and one of the results:
-coordFormat "%03d°%02d′%0d%02.5f″"
042°37′280.00000″ N, 002°05′510.00000″ W
(I don't need five decimal places—I just put that in temporarily to see whether any of the cameras wer being dishonest about the precision.) The three unnecessary spaces can't be helped; they are outside the format string’s control, but I did get rid of others that were in the default.  The leading zero for latitude isn't needed, but it is there because longitude uses the same format string.  One problem is the bogus zero inserted between floor(seconds) and its decimal point. The other problem is the false fractional part.  The default format for that file is 42 deg 37' 28.39" N, 2 deg 5' 51.96" W
Someone's "cheat sheet" said that my second digit should be the total width, including the decimal point, so I changed the seconds to "%08.5f" but all that did was add another bogus zero in front of the decimal point, e.g., 510.00000→5100.00000 (width of ten, not eight!).
A few years ago, I did something similar, and got the correct results.  But I didn't bother to save the script "for future reference."
(Several other SO answers agree with that "cheat sheet.")
It looks like the issue is with the seconds field, for which you have the format specifier %0d%02.5f. I'm not sure what you intended, but there can be only one % for each value to be rendered
If you're formatting longitude then you are dealing with values between -180 and 180. If you want five decimal points then the total width will be
One character for the sign + or -
Three characters for the integer part
One character for the decimal point .
Five fractional digits
giving a total field width of ten. Your full specifier will be %0+10.5f, giving output between «-180.00000» and «+180.00000»
You may use a space flag instead of the +, as in %0 10.5f, which will use a space instead of a + to indicate a positive number, rendering 180 as « 180.00000». The leading zero is there so that zeroes are use to fill the full ten character field with
When dealing with latitude, you will need a total width one character smaller. %0+9.5f will result in a range of «-90.00000» to «+90.00000». Of course you may use the same format specifier as for longitude, which will produce «-090.00000» to «+090.00000». This way the latitude and longitude seconds will have the same number of characters
The %0d is throwing you off. That part of the template is consuming the "51.0" seconds component of the coordinate, leaving nothing for the %02.5d part of the template.
printf "%0d", 51 ===> "51"
printf "%02.5f"; ===> "0.00000"
printf "%0d%02.5f", 51 ===> "510.00000"
So lose the %0d.
The 2 in %02.5f also doesn't do you any good. The number before the decimal place is the minimum length of the field, and the number after the decimal place is the number of decimal places to use. Since 5 decimal places will be printed, the output will be at least 7 characters, and the 2 value will be ignored.
First number is the width, second number is the number of decimal points so what you have currently (%2.5f) appears to be backwards. %5.2f would give you a number that occupies 5 characters and has 2 decimal places. For a number as big as 510, you probably want to make it %6.2f

Converting a floating point number to string

I want to convert a floating point number to string.
f=0.0000
str=num2str(f,4);
This give me this-
str=
0
But I wanted to keep the result till 4 decimal points.I understand using num2str(f,4) results in precision of maximum 4 significant digits after decimal.It is not equal to 4 but maximum and that is why I get this answer.I want to know is there any way to convert this number to string with exactly 4 significant digits after decimal point?
Try using sprintf instead:
str = sprintf('%.4f', f)

Number of decimal digits to show

How to change the number of decimal digits?
Changing the format Matlab can show only 4 (if short) or 15 (if long). But I want exactly 3 digits to show.
To elaborate on Hamataro's answer, you could also use roundn function to round to a specific decimal precision, e.g.: roundn(1.23456789,-3) will yield 1.235. However, Matlab will still display the result in either of the formats you have mentioned, i.e 1.2350 if format is set to short, and 1.235000000000000 if format is set for long.
Alternatively, if you use sprintf, you can use the %g formatting option to display only a set number of digits, regardless of where the decimal point is. sprintf('%0.3g',1.23456789) yields 1.23; sprintf('%0.3g',12.3456789) yields 12.3
You can either use sprintf or do *
var2 = round(var1*1000)/1000