컨텍스트 : Sortable
을 사용하여 정렬하고 있습니다. (MVC 응용 프로그램을C에서 십진수로 기본 반올림 동작 피하기
public ActionResult UpdatePicturePriority(int id, string newpriority)
{
var a = _PictureRepo.GetById(id);
decimal convertDecimal = Convert.ToDecimal(newpriority.Replace(".", ","),);
a.Priority = convertDecimal;
_PictureRepo.Update(a);
return Json(true);
}
몇을 분류 할 (divings) 후, 나는 0,0023565
같은 일부 번호를하지만 내가 컨트롤러에 값을 게시 할 때 0
로 변환되는 것 같습니다 : 컨트롤러에서
$("#sortable").sortable({
update: function (e,ui)
{
nextItemPrio=parseFloat(ui.item.next().find("input[name='Priority']").val().replace(",", "."));
prevItemPrio = parseFloat(ui.item.prev().find("input[name='Priority']").val().replace(",", "."));
currentItemPrio = parseFloat(ui.item.find("input[name='Priority']").val().replace(",", "."));
if ((nextItemPrio < currentItemPrio && prevItemPrio < currentItemPrio)
|| (nextItemPrio > currentItemPrio && prevItemPrio > currentItemPrio)) {
ui.item.find("input[name='Priority']").val((prevItemPrio + nextItemPrio)/2.0);
}
내가 가진). 필자는 코드를 몇 번 나누어도 작동하지 않으므로이 작업을 원하지 않습니다. 나는 내 숫자가 반올림되는 것을 원하지 않는다.
문제는 jQuery, 컨트롤러가 아닌 것 같습니다. 어디에서 정밀도를 잃고 있습니까? –
만약 내가 console.log 내가 0.00055 같은 결과를 얻을하지만, 내가 (데이터베이스에서 결과를받을) 페이지를 새로 고칠 때 나는 0. 컨트롤러를받습니다 : 0.00055 –
흠, 그러면 그 문제는 당신이 정확성을 잃어 가고있는 것 같습니다 데이터베이스 업데이트. 그 값이 데이터베이스에서 기대하는 값인지 확인 했습니까? –