04-10-2013 10:29 AM
I have lots of numbers to infile - some of them have commas in it, some don't. Also, they don't have the same length.
x = 227
y = 99
z = 1033,97
If I try to use stuff like this:
price = input(scan(_infile_,21,'3B'x,'m'),5.2);
price = input(scan(_infile_,21,'3B'x,'m'),comma5.2);
then usually it results in:
x = 2.27
y = 0.99
z = 1033.97
If I take
price = input(scan(_infile_,21,'3B'x,'m'),best.);
price = input(scan(_infile_,21,'3B'x,'m'),5.);
x and y are fine, but the .97 of z is missing.
I really read a lot but still couldn't find a real solution yet.
I'm sure there is a better way than this:
price1= scan(price,1, ',' )
price2 = scan(price,2, ',' )
price3 = 0||'.'||price2
price = price1+price3
If just somebody could tell me?
Thanks a lot!
04-10-2013 10:42 AM
Is the comma supposed to be a decimal, french notation?
If so could you use the translate function to get it to be a period and then read in as a standard number?
04-10-2013 10:50 AM
Hmmm ... I'm not sure you matched up the example 100%. If you tried reading 1033.97 with a comma5.2 informat, you should have gotten 1033.9. At any rate, let's start with the rules.
If the data you are reading contains 3 characters, you can still use a comma5. informat. Your informat is allowed to be wider than the number of incoming characters.
The comma family of informats is correct.
Don't add .2 at the end of the informat. As you have seen by getting 0.99, .2 is an instruction that says, "See if the incoming string contains a decimal point. If it does, use it. But if there is no decimal point, assume that the last two digits read belong after the decimal point."
The bottom line is that you need to find the largest number of characters you will need to read. That number of characters includes everything (decimal point, negative sign, digits before as well as digits after the decimal point). If it is 8, for example, use:
price = input(scan(_infile_, 21, '3B'x, 'm'), comma8.);
04-11-2013 02:58 AM
@LinusH: That's not working.
@Reeza: The comma is supposed to be a decimal, german notation, yes
I think your suggestion might work but it seems still a little like 'MacGyvering'. I'm sure there is a more official way....
@Astounding: Of course you are right and the 1033.97 would have been a 1033.9 with a comma5.2.
About your idea: Unfortunately, using comma8. doesn't work either as my numbers don't contain a decimal point but a decimal comma.
So the 1033.97 becomes a 103397.
Still thankful for any further ideas
Need further help from the community? Please ask a new question.