Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8252545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:35:25+00:00 2026-06-08T00:35:25+00:00

I have a follows code that i have run on LinqPad: void Main() {

  • 0

I have a follows code that i have run on LinqPad:

void Main()
{
    List<VariableData> outputVariableData = 
    new List<VariableData>();

    for(int i = 1 ; i< 100; i ++)
    {
    outputVariableData.Add(new VariableData
        { 
        Id = i,
        VariableValue = .33     
        });
    }

    double result = outputVariableData.Average(dd=> dd.VariableValue);
    double add = outputVariableData.Sum(dd=> dd.VariableValue)/99;
    add.Dump();
    result.Dump();
}

public class VariableData
    {
        public int Id { get; set; } 
        public double VariableValue{ get; set; }
    }

It results

0.329999999999999
0.329999999999999

When i check the average of same numbers in the excel sheet with formula =AVERAGE(A1:A101) and it return .33 as it is.

Actually i am drawing chart with this data and average value is showin on the chart, which making the chart drawing so absert and chart is not able to manage such type of value.

I am little confused about the output of these both, i suppose excel automatic round the value. so i have simple and little silly question that is output of my extension method is correct??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:35:26+00:00Added an answer on June 8, 2026 at 12:35 am

    As noted, excel gives you a nice rounded version. For displaying of numbers this may be a very useful read: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

    There is also http://msdn.microsoft.com/en-us/library/f5898377 available.

    What’s the relevance of Standard Numeric Format Strings You Literally Ask?

    Easy – the problem isn’t that the numbers wrong – it’s perfectly fine given the inaccuracies of floating point numbers. However displaying these numbers can be an issue – it’s not what we expect nor is it useful. However, if we spend a few seconds defining how we want our numbers presented…

    void Main()
    {
        List<VariableData> outputVariableData = 
        new List<VariableData>();
    
        for(int i = 1 ; i< 100; i ++)
        {
        outputVariableData.Add(new VariableData
            { 
            Id = i,
            VariableValue = .33     
            });
        }
    
        double result = outputVariableData.Average(dd=> dd.VariableValue);
        double add = outputVariableData.Sum(dd=> dd.VariableValue)/99;
        add.Dump();
        add.ToString("P0").Dump();
        add.ToString("N2").Dump();
        result.Dump();
        result.ToString("P0").Dump();
        result.ToString("N2").Dump();
    }
    
    public class VariableData
    {
            public int Id { get; set; } 
            public double VariableValue{ get; set; }
    }
    

    Suddenly we get the output we want:

    0.329999999999999
    33 %
    0.33
    
    0.329999999999999
    33 %
    0.33
    

    The problem now isn’t trying to massage the numbers to perfection, or using unusual datatype – but spending a few minutes figuring out what options are available and making use of them! It’s easy to do and very useful in the long run 🙂

    Of course, this should only be used for displaying data – if you need to round data for computational reasons then I suggest looking into Math.Round etc.

    Hope this answers your Q.

    Supplemental:

    This is another option that works in a very similar vein: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx It explains how to do things like:

    void Main()
    {
        0.31929.ToString("0.##%").Dump();
        0.ToString("0.##%").Dump();
        1.ToString("0.##%").Dump();
    }
    

    Which results in:

    31.93%
    0%
    100%
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a section of code that can be summarised as follows; void MyFunc()
The code that I have is as follows: <!DOCTYPE html> <html> <head> <script src=javascript/jquery.js
I have php code that puts some values into an Array as follows: $hunter=addslashes($MessageArray[1]);
I have code to run sql query in ruby as follows sql = ActiveRecord::Base.connection()
I have some code that is structured as follows from my.modules import MyClass Class
I have some code that throws an exception as follows. if (jobFinished) { ...
I have a line of code as follows: $('#type').val(target).trigger('change'); It opens a new div(it
I have code as follows: $(#item_select).change(function() { var params = $(#item_select option:selected).val(); $.post('/account/ar_form.php', {idata:
I have a piece of javascript code as follows: var data = { ...
Currently, I have some code as follows template<typename Type> Type* getValue(std::string name, bool tryUseGetter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.