Float numbers from "." to "," for Latitude and Longitude

Apr 22, 2009 at 9:53 AM
Hi guys,

I'm a newbie on ASP.NET and I have a problem with float numbers for Latitude and Longitude.

My Windows 2008 Server is having  regional settings German (Austria) and DB is expecting float numbers to have comma as separator (48,2156748040486), but the Virtual Earth API  is populating Latitude and Longitude fields with float numbers having point as separator (48.2156748040486), if I submit create form I get an error for Latitude and Longitude fields, if I change "." to "," I can insert a dinner in DB but I have problems when I extract and display this dinner.

How can I fix this problem?

Thanks!
Coordinator
Apr 22, 2009 at 9:21 PM
Wow, that's a great bug. I need to think about that. Until then, force the server side to en-us in the web.config:

<configuration>
   <system.web>
      <globalization culture="en-US" />
   </system.web>
</configuration>
Sep 9, 2009 at 11:45 AM

I'm from Belgium and I bumped into the same problem.

My solution was to create a custom modelbinder that replaces the "wrong" decimal seperator for values of type double.

Find the code in this blogpost:

http://www.crydust.be/blog/2009/07/30/custom-model-binder-to-avoid-decimal-separator-problems/

Jan 13, 2010 at 7:39 PM

Hi,

I would be glad to have a solution for this problem !!!!

It's still bugged

Thanks

Coordinator
Jan 22, 2010 at 5:49 PM

Yes, Sorry, we are fixing many bugs right now and will have a new release soon.

Mar 1, 2010 at 7:45 PM

 

]string LatitudeUSA

        {
            get { return this.Latitude.ToString().Replace(',', '.'); }
            set { this.Latitude = Convert.ToDouble(value.ToString().Replace('.', ',')); }
        }
        public string LongitudeUSA
        {
            get { return this.Longitude.ToString().Replace(',', '.'); }
            set { this.Longitude = Convert.ToDouble(value.ToString().Replace('.', ',')); }

 

 

 }

Hi,

my solution was to include two new attributes (LatitudeUSA and LongitudeUSA) accessing the originals (Latitude and Longitude).

        public string LatitudeUSA

        {

            get { return this.Latitude.ToString().Replace(',', '.'); }

 

            set { this.Latitude = Convert.ToDouble(value.ToString().Replace('.', ',')); }

        }

        public string LongitudeUSA

        {

            get { return this.Longitude.ToString().Replace(',', '.'); }

 

            set { this.Longitude = Convert.ToDouble(value.ToString().Replace('.', ',')); }

        }

I had to change the references to these attributes in the application.

I'm new to MVC, I do not know if this is a good practice.

I had to include them in the filter Bind:

[Bind (Include ="Title, Description, EventDate, Address, Country, ContactPhone, Latitude, Longitude, LatitudeUSA, LongitudeUSA ")]

 

May 20, 2012 at 7:48 PM

"herberts

I have followed your example code, however I'm not being able to make it work.

More clarification is needed.

How should the ActionResult be and what about the view.

May 28, 2012 at 4:26 PM

Hi samarmir,

 

I didnt change de view or actionresult. I just created these two new properties and used them instead of the original. The remainder is the same as the book example.

May 29, 2012 at 7:28 AM
Hi Herbert!
Thanks for taking time to answer and thanks for your answer.

Sincerely
Samar

On Mon, May 28, 2012 at 6:26 PM, herberts <notifications@codeplex.com> wrote:

From: herberts

Hi samarmir,

I didnt change de view or actionresult. I just created these two new properties and used them instead of the original. The remainder is the same as the book example.

Read the full discussion online.

To add a post to this discussion, reply to this email (nerddinner@discussions.codeplex.com)

To start a new discussion for this project, email nerddinner@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com