Skip to content

Example code incorrectly calculates percentage #11121

Open
@jcowin-sigmadzn

Description

@jcowin-sigmadzn

Type of issue

Code doesn't work

Description

If the intent was to show the progress percentage, parentheses are needed around (ctr + 1):

for (int ctr = 0; ctr < 500; ctr++)
    Console.WriteLine($"Line {ctr + 1} of 500 written: {(ctr + 1) / 500.0:P2}");

Example Output

Line 498 of 500 written: 99.60%
Line 499 of 500 written: 99.80%
Line 500 of 500 written: 100.00%

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.standardoutput?view=net-8.0#remarks

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Diagnostics/Process.xml

Document Version Independent Id

981e4b00-7db9-eeab-ce84-6f23ecde07a1

Platform Id

8ec5d3e5-25ef-3c4a-5a94-e2d67ac91358

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions