从数字强制转换时,值必须是小于无穷大的数字 [英] When casting from a number the value must be a number less than infinity

查看:133
本文介绍了从数字强制转换时,值必须是小于无穷大的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的控制器中,我收到以下错误从数字强制转换时,该值必须小于无穷大".这发生在以"var zone ..."开头的行上.

In my controller below I'm receiving the following error "when casting from a number the value must be a number less than infinity". This occurs on the line that begins "var zones..."

这是我的控制器

    public JsonResult LatLng()
    {
        var zones = zoneRepository.GetCoordinates().ToList();

        //return Json(zones, JsonRequestBehavior.AllowGet);.
        return Json(new { zones = zones }, JsonRequestBehavior.AllowGet);
    }

这是我的模特

    public IQueryable<Zone> GetCoordinates()
    {
        return db.Zones;
    }

在我的数据库表中,我有一列是数字类型的,三列是float类型的.有没有办法找出我的代码反对的值?我最好的猜测是,这与我对浮点数的使用有关.但是我不确定如何进行调试.任何指向我指出纠正此错误方向的指导都将不胜感激.

In my database table I have one column that is of type numeric and three columns that are of type float. Is there a way I can find out what value(s) my code is objecting to? My best guess is that this has something to do with my use of floats. However I'm not sure how to go about debugging this. Any guidance that points me in the direction of fixing this error would be greatly appreciated.

注意-仅在运行时出现错误

Note - there error only occurs at runtime

推荐答案

我将数据库中的纬度和经度列从float转换为十进制.这解决了我的问题.如果有人想花时间解释为什么这样做,我很乐意将其标记为答案.例如,当目视检查数据时发现小数点左右两边的位数都不超过几位数时,我的坐标怎么会大于无穷大?

I converted my latitude and longitude columns in the database from float to decimal. This solved my problem. If someone would like to take the time to explain why this worked I will gladly mark that as the answer. For example, how is it that my coordinates are greater than infinity when a visual inspection of the data reveals that none are more than a few digits to the right and left of the decimal point?

这篇关于从数字强制转换时,值必须是小于无穷大的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆