Monday, December 21, 2009

Recurring issue: str2num

There is a general problem with string to numeric conversion in Ax, which seems to resurface now and again.
Last time around when we faced this problem, we were working in the Product Builder modules. We had variables setup with default values like this: 3.200,00 mm
But when Ax loaded the configuration form, the string values were converted to 3 (no decimal value setup - values divided by 1000). Ax had interpreted the thousand separator as the decimal separator. It's easy to test:


As the values stored for the configurated product models are all converted to string values (table PBATableInstance), there are 2 possible approaches to this problem.

1. Make sure the saved value is stored without the thousand separator. ("3200,00" converts ok to 3.200,00)

2. Make sure the retrieved value is converted back to a numeric value in the right way.

We choose the latter approach. We edited Class PBABuildForm\fillDataSource, where the default values of the product model are set up.

pbaTmpBuildForm.Comma = str2num(strrem(pbaTableInstance.Value,'.'));

(Ax 2009 SP1 - no HF)

No comments:

Post a Comment