upon a time I’ve been suggested for this expression below who filter out data you see in the picture. Everything worked till I’ve got negative currencies values who raise the error: Assign: Input string was not in a correct format.
How following expression could be fixed to work with negative values?
(From myRow In dtData.AsEnumerable() Where Double.Parse((myRow(“Balance Amount”).ToString.Trim), NumberStyles.Any, New CultureInfo(i_strCultureInfo)) >= ((Double.Parse((myRow(“Amount”).ToString.Trim), NumberStyles.Any, New CultureInfo(i_strCultureInfo))/100) * i_intDueAmountThreshold) Select r = myRow).toList
For an analysis over the entire datatable do the following:
Set a breakpoint
Debug and get paused
Run following statement within the immediate panel
dtData.AsEnumerable.Where(Function (x) Not Double.TryParse(x("Balance Amount").ToString.Trim, NumberStyles.Any, new CultureInfo("es-ES"), nothing)).toList
So you will get all datarows having issue with the current configured Parse Strategy
Hi Peter,
thanks a lot! seems I’ve some records for US … so how could I make calculation avoid error and do not change anytime “culture” ? could be CultureInfo.InvariantCulture the solution instaed of CultureInfo(“es-ES”)?
Another way do not elegant could be string replace ?
Thanks.
Br.
Marco.
Assign Activity
arrCISet = new CultureInfo(){ new CultureInfo(“en-US”), new CultureInfo(“es-ES”)}
(From myRow In dtData.AsEnumerable()
Let ci1 = arrCISet.Where(Function (c1) Double.TryParse(myRow("Balance Amount").ToString.Trim, NumberStyles.Any, c1, nothing)).First()
Let ci2 = arrCISet.Where(Function (c2) Double.TryParse(myRow("Amount").ToString.Trim, NumberStyles.Any, c2, nothing)).First()
Let n1 = Double.Parse(myRow("Balance Amount").toString.Trim, NumberStyle.Any, c1)
Let n2 = Double.Parse(myRow("Amount").toString.Trim, NumberStyle.Any, c2)
Where n1 >= (n2 / 100) * i_intDueAmountThreshold
Select r = myRow).toList
it is one of a few options.
We would recommend adapting if needed with some prechecks…
We would also recommend to let it fail in case of wrong CIs instead of String Manipulations
if also needed then typical handling is to filter out unrecognized rows in advance and route it to a resolution flow
Thanks! that works or better does not give me any exception! … again could you please explain in words status of current variables e.g. what n1 and n2 contains at the time?
Could works also works adding new CI (e.g. de-DE) alltogether ?
Tkx.
one thing to add
123.45 in default is different to e.g. German locals (group seperator vs. decimal seperator)
it would risk to catch the wrong CultureInfo
Hi Peter,
I wanted to introduce your LINQ script and it works somehow (or better has no exceptions) but logic seems is not what i want (maybe I was not clear) so I reproduced the logic attached in old way and would be very nice to have the correspond LINQ script.
Thanks. Br. Marco.