Problem with sub command (awk) and numbers

Hi,

I am trying to perform a simple soustraction between two floating numbers and cannot get it done for some reason due to the use of the sub command.

The following is the straight-forward result of the soustraction:

[cscyabl@kna-bassdev scripts]$ echo | gawk '{a=968;b=967.99;c=a-b;print c}'                      
0,01

Now we are working with a different locale where the decimals delimiter is not a "." but a ",". You can see that on the above output and the way it's displayed.

Therefore I want this in:

sub(/,/,".", a)

And it does not work for some strange reason:

[cscyabl@kna-bassdev scripts]$ echo | gawk '{a="968";b="967,99";sub(/,/,".",a);sub(/,/,".",b);print a" "b;c=a-b;print c}'
968 967.99
1

The diff is now 1 and I can't explain why...
Any help would be much appreciated.

"sub" should be done after performing mathematical operation:

echo | gawk '{a="968";b="967,99";c=a-b;sub(/,/,".",a);sub(/,/,".",b);sub(/,/,".",c);print a" "b;print c}'
gawk 'BEGIN{a=968;b=967.99;c=a-b;printf "%.2f",c}'