on 2018 Mar 18 5:22 PM
I have provided 3 screen shots to make better since. My problem is I am trying to make a formula that displays a fraction. In my database I have two of the same fields one shows (Width) which shows a decimal. and the other (WidthF) which shows a fraction and is a sting if that makes a difference. All I need is to use the (WidthF) and subtract 1 to make the forumula. I can make it work with just the (Width) but it displays the same answer in a decimal I just need it in a fraction.
Request clarification before answering.
Another option is to split your fraction text.
Assuming fraction always has format
int space fraction eg 10 4/7 you can use instr()
@widthF-1
local stringvar Int;
Local stringvar Fract;
int := right(WidthF, instr(WidthF, ' ')-1);
Fract:= mid(WidthF, instr(WidthF, ' ')+1, X) // X = max length of WidthF
Totext(Tonumber(Int)-1,0,")&' '&Fract
Ian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Brayden,
The problem with fractions is there is no way for a database to show it as a number. If you take the fraction of 1/2 as a number, the database assumes this is a formula and will always display it as .5 because that's the numerical value of 1/2.
You need to take the fraction and convert it to a decimal. Do your calculation and build the fraction as a string.
The best way to do this is in the database, as Ian suggested. Because you should have access to the decimal value and do your calculation there. Now you can either build the fraction as a string in the database and just display it in Crystal.
The hard part in Crystal is taking your fraction as a string and converting it to a number. It's possible but the formula to do it is pretty advanced.
Fix it at the source and use Crystal for what it's meant for, displaying data.
Good luck,
Brian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay So in this database I can pull from two different locations. (Width) which gives me the correct number but just gives it in a decimal number and this is not a string. Second is (WidthF) which is a string both display the same info just one is a fraction and one is not same as one is a string and one is not. So if the strings are so difficult to deal with why cant I just use the (Width) which is not a string a number and subtract my 1 then turn it into a Fraction. If I use the SQL and use the string I can add anyting I want but when placing the subtract - sign it does not work.
Hi Brayden,
You can't do mathematical calculations on a string. My guess is the "+" is not doing an addition but appending the 1 to the string. So instead of 1 + 1/2 it's displaying as "1 1/2" as a string and not actually 1.5. It would be the same if you did something like:
1 + "This is my String"
Would come out as "1 This is my String".
The reason your fraction is a string is because the "/" is not a numeric character. Fractions are not a numeric data type. They are a representation of a decimal. So to do a valid arithmetic calculation, you must use an actual numeric type like your Width column.
My guess is your system may have a function to convert a number to a Fraction string. How that's done is internal to your system and we can't help.
I had a search and there is a function that will take your decimal and convert it to a fraction. You will have to download the math function and load it into Crystal.
https://apps.support.sap.com/sap/support/knowledge/public/en/1456455
Follow the instructions. It should work for your version of Crystal.
Good luck,
Brian
I thought you were using Crystal Formulae for Width and WidthF.
If you can do it in SQL then that is the best option, just add another field which would be WidthF-1
Ian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried using the SQL and pretty much came up with the same thing. I created the field WidthF-1 and used the "Width" database and it does give me the correct number but still in a decimal. I did the same thing with the "WidthF" field and it doesn't create a error but only gives me two numbers that are incorrect? What were you thinking the SQL would do to fix this problem?
You are going to have to explain your self better as I am not that computer literate. All these database fields were created by a 3rd party in a program that I use I am just editing the aragnement and the information displayed inside of crystal reports. Can I do as you say "Copy and make a WidthF2" inside of crystal reports? Why can I not just use the Width database alrady there that works correctly and just convert the numbers to a fraction instead of a decimal. This was just seems eaiser if it will work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must subtract the 1 before you convert to fraction as your fraction is a string.
Just copy your WidthF formula eg WidthF2 and subtract the 1 in the numerical part and then create another fraction
Ian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
30 | |
9 | |
9 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.