Format output type double with dot instead of comma

4

I have a collection of coordinates to popular repeater, with city name, latitude and longitude.

 .aspx

 <form id="form1" runat="server">

    <div id="repetidor">
        var markers = [
                <asp:Repeater ID="rptMarkers" runat="server" Visible="true">
                <ItemTemplate>
                  cidade: <%# Eval("NomeCidade")%>,
                     lat: <%# String.Format(System.Globalization.CultureInfo.GetCultureInfo("en-US"), "{0:D}", Eval("Latitute")) %>,
                     lng: <%# String.Format(System.Globalization.CultureInfo.GetCultureInfo("en-US"), "{0:D}", Eval("Longitude")) %>,
                </ItemTemplate>
            <SeparatorTemplate>
                    -
            </SeparatorTemplate>
                </asp:Repeater>
        ]
    </div> 

So I get the coordinates;

     .aspx.cs            

       (...)
                var address = coordenadas.NomeCidade + ", Brasil";
                var locationService = new GoogleLocationService();
                var point = locationService.GetLatLongFromAddress(address);
                coordenadas.Latitude = point.Latitude;
                coordenadas.Longitude = point.Longitude;
                coordenadasColecao.Add(coordenadas);

        (...)
            rptMarkers.DataSource = coordenadasColecao;
            rptMarkers.DataBind();
        (...)

I'd like it to look like this: 46.1475292 instead of 46.1475292

    
asked by anonymous 22.09.2016 / 18:37

3 answers

2

Convert to String then use the Replace command from String class :

<%#Eval("Latitude").ToString().Replace(",",".")%>

References:

23.09.2016 / 02:17
3

I do not know how you're getting this value, as it usually comes with period , as can be seen in the official GitHub of the API you are using.

However, you can make a simple Replace() , if you wish.

Console.WriteLine(String.Format(System.Globalization.CultureInfo.GetCultureInfo("en-US"), "{0:D}", "46,1475292").Replace(",","."));

You also have strings to format from way you want.

On the other hand, you can look at the question of How to format Double that I think will have some more ideas of how do what you want.

    
23.09.2016 / 01:01
2

Use String.Format and force Globalization

<%# string.Format(new System.Globalization.CultureInfo("en-US"), 
                              "{0:D}", Eval("Latitude")) %>
    
22.09.2016 / 19:06