Fraction issue in Crystal Report - crystal-reports

I am facing a strange problem in crystal report 2008
I have a table (mytable) with two columns col1 is string and col2 is float(15)
Below are values in table
Col1 Col2
AA 5.82518987E-5
BB 5.88383009E-5
Created a report in crystal report and placed mytable values on report for col1 it displays correct value but for COL2 it always displays FOR AA "0.0000582519" AND FOR BB "0.0000588383" instead of actual value in the table.
This is what in Crystal report instead of actual value.
Col1 Col2
AA 0.0000582519
BB 0.0000588383
Please help
Thanks

CR has the interesting limitation that the highest precision numeric value it can display is 10 decimal places (this includes trying to use the totext() function to cast the number to a string). This means that any float over that precision will be rounded at that tenth decimal.
Because of this and the fact that you're using a float which is precise up to 15 digits, the quick and dirty solution is to just manually convert to scientific notation by moving your decimal place over 5. You can accomplish this with something like:
totext({table.numeric} * 10^5,10) & "E-5"
Obviously, this will just indiscriminately convert all your numbers in Col2 to scientific notation whether they require it or not, so you may wish to add some additional conditional processing.
Note that if you Google "Crystal Reports scientific notation" you can find some custom functions to do that for you... but just be careful because a lot of these functions do not take the additional precision into account and WILL result in a much less precise number. In fact, the very first hit (HOw to display Number in Scientific Notation in version 2008) will chop that precision down to 10 digits in the very first line by using the totext() function.

Related

Why are 2 numeric values with many decimal places considered equal in postgres?

Why is select (1.9999999999999999+2)/2 = (1.9999999999999999999999999999999999+2)/2 equal to true in postgres? Doing select pg_typeof((1.9999999999999999999999999999999999+2)/2) shows type numeric, which the docs say are exact numbers are should support thousands of digits after the decimal.
select 1.9999999999999999 = 1.9999999999999999999999999999999999 returns false as expected.
Why does select (1.999999999999999+2)/2 show 1.9999999999999995 like I'd expect but adding an extra "9" to the end shows 2.0000000000000000? Shouldn't the extra digit increase the precision and I should see the extra "9" in the result too?
In what cases can I be sure I won't see this in my queries when doing arithmetic on numeric types?
The numeric expression on the left side has only 16 decimal digits. The overall expression evaluation is limited to that precision.
Try this:
select (1.9999999999999999000000000000000000+2)/2 = (1.9999999999999999999999999999999999+2)/2
And you'll get false because you are now comparing 34 decimals on both sides (if I counted right).

How to avoid CIRCULAR REFERENCE in TABLEAU using LOOKUP and PREVIOUS_VALUE?

Hello!
In Excel I have 2 columns C and D with formulas in there for a specific purpose.
As an Example I have here cells C12 and D12 in these 2 columns to show he formulas.
C12 = 0.001855 * B12/E12 + 0.998145 * (C11+D11)
D12 = 0.981119 * (C12-C11) + 0.018881 * D11
Let's say the C-column variable is "Running Base" and the D-column variable is the "Growth" and the rows are months. And say I want to copy these formula's to a Tableau worksheet with months in the rows.
You see that C12 is using both it's own previous value C11 (the lag -1 of C) and the lag -1 of D (D11). I can find C11 in the formula in TABLEAU using the PREVIOUS_VALUE function and the previous value of D with the LOOKUP([D],-1) function (the B12 and E12 are not important for the discussion).
Then D12 is also using it's own previous value D11 and both C12 and its previous value C11. Of course we can do similar TABLEAU exercises here, but you already feel a CIRCULAR REFERENCE error coming up ;-).
So, there is no actual CIRCULAR REFERENCE and it's working in Excel. But I do understand why TABLEAU is giving one and I am sure there must be a work-round to this.
Can anybody help please???
Thx very much in advance!!
Herman Mentink
One way to solve this is to drop the calculation in Details part of the Marks and then reference the rows of that field in calculation which doesn't create a circular reference else you are correct tableau will create a circular reference error as behaviour is different from Excel.
Edit----------------------------------------------------------------
Not just a tool tip infact you can use those in calculated fields aswell, Few months back I have implemented same in my report.
A calculation creates 4 rows in my report and I need to do (1st row+4th row) in the same column, so I dropped the calculation in Detail on the Marks and referred same another calculated field. Just check the below example code:
LOOKUP(ATTR([Values]),FIRST()+4) + LOOKUP(ATTR([Values]),FIRST()+1)
Values is the calculated field now above caluction is referring to Values and picking rows 2 and 5 which I can't use directly on the Values column if I drop Values on Text in Marks
In the above image values in detail is original calcualtion and the one I used in text is the referring to values and displaying.

printmat function: Decimal and percentage

I am very new to MATLAB. I am sorry if my question is basic. I am using "printmat" function to show some matrices in the command console. For example, printmat(A) and printmat(B), where A = 2.79 and B = 0.45e-7 is a scalar (for the sake of simplicity).
How do I increase the precision arbitrarily to seven decimals? For example: my output looks like 2.7943234 and B = 0.00000004563432.
How do I add a currency (say dollar) figure to the output of printmat?
How do I add a percentage figure (%) to the output of printmat?
Note: The reason I use printmat is that I can name my rows and columns. If you know a better function that can do all above, I would be glad to know.
Regards Mariam. From what I understand, you would like to display the numbers and show their full precision. I am also newbie, If I may contribute, you could convert the number data to string data (for display purposes) by using the sprintf function.
I am using the variable A=2.7943234 as example. This value will not display the full precision, instead it will display 2.7943. To show all the decimal tails, you could first convert this to string by
a = sprintf('%0.8f',A);
It will set the value a to a string '2.79432340'. The %0.8f means you want it to display 8 decimal tails. For this example,%0.7f is sufficient of course.
Another example: A=0.00000004563432, use %0.14f.
A=0.00000004563432;
a=sprintf('%0.14f $ or %%',A);
the output should be : '0.00000004563432 $ or %'.
You could analyze further in https://www.mathworks.com/help/matlab/ref/sprintf.html
You could try this first. If this does not help to reach your objective, I appreciate some inputs. Thanks.
The printmat function is very obsolete now. I think table objects are its intended successor (and functions such as array2table to convert a matrix to a table of data). Tables allow you to add row and column names and format the columns in different ways. I don't think there's a way to add $ or % to each number, but you can specify the units of each column.
In general, you can also format the display precision using format. Something like this may be what you want:
format long

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

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