Which format do I need if I have some numbers with commas?

Solved
Occasional Contributor
Posts: 9

Which format do I need if I have some numbers with commas?

Hi all!

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.
For example:

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

or

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:

price= upcase(compbl(scan(_infile_,21,'3B'x,'m')));

price1= scan(price,1, ',' )

price2 = scan(price,2, ',' )

price3 = 0||'.'||price2

price = price1+price3

If just somebody could tell me?

Thanks a lot!

Accepted Solutions
Solution
‎04-11-2013 05:12 AM
Super User
Posts: 5,888

Re: Which format do I need if I have some numbers with commas?

Sorry, numx. should do the work.

Data never sleeps

All Replies
Super User
Posts: 5,888

Re: Which format do I need if I have some numbers with commas?

comma.

Data never sleeps
Super User
Posts: 23,778

Re: Which format do I need if I have some numbers with commas?

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?

Super User
Posts: 6,785

Re: Which format do I need if I have some numbers with commas?

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

Good luck.

Occasional Contributor
Posts: 9

Re: Which format do I need if I have some numbers with commas?

@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

Solution
‎04-11-2013 05:12 AM
Super User
Posts: 5,888

Re: Which format do I need if I have some numbers with commas?

Sorry, numx. should do the work.

Data never sleeps
Occasional Contributor
Posts: 9

Re: Which format do I need if I have some numbers with commas?

Perfect! Thanks a lot!

🔒 This topic is solved and locked.