의 nullable decimal 변수에 저장하는 반올림없이 10 진수 값을 소수 자릿수 4 개로 형식화 (잘림)하려고했습니다. 예를 들어, 나는 (31.8182 반올림 NOT)10 진수 값 서식 지정 방법 C#
31.8181
에
31.818181818181818181818181818M or 31.818181818181818181M or 31.81818M
처럼 진수로 변환 그리고 null 허용 진수 변수에 저장하고 싶습니다. decimal formatting without rounding .net 및 Stop Rounding In C# At A Certain Number 을 시도했지만 null 가능 십진수는 없습니다. 여기
는
private decimal? ReturnNullableDecimal(decimal? initValue)
{
//e.g. initValue = 35M;
initValue = 35M; //just to debug;
decimal? outputValue = null;
if (initValue != null)
outputValue = initValue/(decimal)1.10;
//now outputValue is 31.818181818181818181818181818M
outputValue = Convert.ToDecimal(string.Format("{0:0.0000}", outputValue)); // <- this should be 31.8181 but gives 31.8182
return outputValue;
}
사람이 도와 주실 수있는 코드?
a.net에서 뱅커 라운딩이 기본값입니다. 중간 점 라운딩이 필요합니다. –