abp icon indicating copy to clipboard operation
abp copied to clipboard

Floating number binding goes wrong in different cultures

Open cotur opened this issue 6 years ago • 3 comments

I have an entity that has decimal properties.

When I create new records int different cultures, floating point properties parsing wrong.

resim

I send with .(dot) in Turkish also. But in Turkish culture floating points represented with ,(comma)

resim

May framework support to handle it by custom modelbinder or it is required to implement individually?

cotur avatar Apr 14 '20 09:04 cotur

hi @cotur Which project can reproduce this problem?

maliming avatar Apr 15 '20 09:04 maliming

By default, the model binding uses invalid culture in querystring and router to get the value, and uses the current culture to get the value in the form.

This may cause some potential binding issues. For example, we can't use the culture format (time and currency, etc.) to pass parameters in the querystring.

Solution:

  1. We can use json to pass request parameters. Because the number format in json is fixed. But this requires more coding.

  2. We can format the parameters according to the current culture in the js code and then pass it to the server. eg: parseFloat("516.89").toLocaleString(abp.localization.currentCulture.cultureName)

  3. We can also write some custom model bindings on the server side to be compatible with some situations, but we cannot cover all.

In short, it is not easy for an application to work flawlessly in different cultures.

@cotur @hikalkan What do you guys think?

maliming avatar Apr 15 '20 13:04 maliming

It seems it is related to UI (jquery validation) rather than the server side. Please create a new issue if you need.

hikalkan avatar Apr 20 '20 09:04 hikalkan