简体   繁体   English

小数损失精度类型的Kendo网格列

[英]Kendo Grid Column of type Decimal Losing Precision

I have bound some data to a Kendo grid and the problem I am running into is that the grid seems to only want to show two decimal places instead of 5 or 6 or whatever the real value is for the longitude and latitude columns. 我已经将一些数据绑定到Kendo网格,而我遇到的问题是,网格似乎只希望显示两位小数而不是5或6,或者不显示经度和纬度列的实际值。

Here is the code in my view: 这是我认为的代码:

<div class="gridPadding">    
    @(Html.Kendo().Grid((IEnumerable<DealerPortal.Models.DealerViewModel>)ViewData["DealerResults"])
                .Name("dealerSearchResults")
                .Columns(columns =>
                {
                    columns.Bound("DealerID");
                    columns.Bound("DealerName");
                    columns.Bound("TerminalID");
                    columns.Bound("Status");
                    columns.Bound("Address1");
                    columns.Bound("State");
                    columns.Bound("PhoneNumber");
                    columns.Bound("Email");
                    columns.Bound("Latitude");
                    columns.Bound("Longitude");
                    columns.Bound("EpayRetailerID");
                })
                .DataSource(dataSource => dataSource.Server().Model(model => model.Id(d => d.DealerID)))
                .Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
                .Sortable()
            )
        </div>

Here is the DealerViewModel class: 这是DealerViewModel类:

public class DealerViewModel
{        
    public long DealerID { get; set; }
    public string DealerName { get; set; }
    public string Address1 { get; set; }
    public string PhoneNumber { get; set; }
    public string Email { get; set; }
    public decimal? Latitude { get; set; }
    public decimal? Longitude { get; set; }
    public string EpayRetailerID { get; set; }
    public string TerminalID { get; set; }
    public string State { get; set; }
    public char Status { get; set; }
}

When I step through the code I can see that ViewData["DealerResults"] holds the correct values for longitude and latitude, but the grid displayed on the webpage cuts it off after 2 decimal places. 当我单步执行代码时,我可以看到ViewData["DealerResults"]保留了正确的经度和纬度值,但是网页上显示的网格将其截断了两位小数。 I only have the nullable decimal type to satisfy some error I was getting further upstream, but it doesn't seem like that should be the problem. 我只有可为空的十进制类型来满足我在更上游时遇到的一些错误,但似乎不应该是问题所在。

I also couldn't seem to find the way to format these values as sometimes they are negative values and the amount of decimal places changes. 我似乎也找不到找到格式化这些值的方法,因为有时它们是负值,并且小数位数发生了变化。

I tried columns.Bound("Latitude").Format("00.000"); 我尝试了columns.Bound("Latitude").Format("00.000"); which only made every value "00.000" and columns.Bound("Latitude").Format("##.###"); 这仅使每个值都为“ 00.000”和columns.Bound("Latitude").Format("##.###"); which also made every value "##.###". 这也使每个值都为“ ##。###”。

Any ideas? 有任何想法吗? Thank you 谢谢

Try columns.Bound("Latitude").Format("{0:n6}"); 试试columns.Bound("Latitude").Format("{0:n6}"); It will fill in all decimal places till the 6th place. 它将填充所有小数位直到第6位。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM