dotnet / dotnet/docs

Number formatting rounding discrepancy

Open
#22,089 12 comments 0 reactions 1 assignee Claimed by @tannergooding View on GitHub
dotnet-fundamentals/svc okr-quality waiting-on-feedback
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
19h 10m
Merged PRs (30d)
268

Description

[Enter feedback here]
Tested on .net core runtime 3.1.10

double num = 1234.5;
var str = num.ToString("G4"); (1234, the rounding is using MidpointRounding.ToEven which is the expected behavior)

double money = 12.345;
var moneyStr = money .ToString("C"); ($12.35, the rounding is using MidpointRounding.AwayFromZero, the result is expected to be $12.34 since formatting should be using MidpointRounding.ToEven)

decimal num2 = 1234.5m;
var str2 = num2.ToString("G4"); (1235, the rounding is using MidpointRounding.AwayFromZero, the result is expected to be 1234 since formatting should be using MidpointRounding.ToEven)

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 0ae38fce-fc98-9420-6b0b-ceee4e885f2d
* Version Independent ID: f23035e0-f271-b48c-f9a9-8582be80b4ad
* Content: [Standard numeric format strings](https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#feedback)
* Content Source: [docs/standard/base-types/standard-numeric-format-strings.md](https://github.com/dotnet/docs/blob/master/docs/standard/base-types/standard-numeric-format-strings.md)
* Product: **dotnet-fundamentals**
* GitHub Login: @adegeo
* Microsoft Alias: **adegeo**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.