开发者

Convert float value to string

I have a property like this:

 public float Lat{
        get {
            float lat;
            if (!float.TryParse(hdnLat.Value, out lat))  
            {
                throw new NotImplementedException();
            }

            return lat;
        }
        set { 
            hdnLat.Value = value;  // Line 43
        }
    }

I got Latitude and Longitude from Google Maps and i get the cordinates from two asp.net hiddenfields.

<asp:HiddenField ID="hdnLat" runat="server" />
<asp:HiddenField ID="hdnLng" runat="server" />

I store my latitude and longitude as float in my databas so i have to conve开发者_开发问答rt it to float right?

How can i convert my cordinates to correct format?

Visual Studio givs me this error:

Can not implicitly convert type double to string Line 43

How can i solve this problem?


Since hdnLat.Value is of type string, when you assign to it, the item you assign must also by of type string. So if you want to assign value, you have to convert it into a comparable item of type string. And you can do that like this:

hdnLat.Value = value.ToString();

Which is exactly what the error message "can not implicitly convert type double to string" is trying to tell you. You should read this message as "I see you're trying to use a double where I expected a string. I tried to figure out how to convert it, but I cannot. Could you tell me explicitly how to convert it?"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜