0

is there any way i can get a double to contain more than default 13 (17 in JS) decimal points in C# or JS? Like a double with first 25 PI digits?

Andrej Ilic
  • 21
  • 1
  • 5
  • 1
    use Decimal then – Tim Schmelter Oct 16 '18 at 15:55
  • Read the docs at https://learn.microsoft.com/en-us/dotnet/api/system.double?view=netframework-4.7.2. You get what you get. And, you can't represent everything you expect to represent (https://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/). The `decimal` type can get around some of this. – Flydog57 Oct 16 '18 at 16:04
  • yes but all System.Math functions return a double. @TimSchmelter – Andrej Ilic Oct 16 '18 at 16:05
  • @AndrejIlic: no, there are often overloads that take a `Decimal` and return one, for example [`Math.Ceiling`](https://learn.microsoft.com/en-us/dotnet/api/system.math.ceiling?view=netframework-4.7.2#System_Math_Ceiling_System_Decimal_). Only methods where it doesn't make sense to use `decimal` like [`Math.Asin`](https://learn.microsoft.com/en-us/dotnet/api/system.math.asin?view=netframework-4.7.2) take only `double`. – Tim Schmelter Oct 16 '18 at 16:09

1 Answers1

1

Standard Data Types

Both the double in C# and he normal number data type in JavaScript is stored as 64 bit number, see https://www.w3schools.com/js/js_numbers.asp and https://www.tutorialspoint.com/csharp/csharp_data_types.htm

This limits the number of decimal points that can be represented. However, there are appropriate Libraries to handle this issue

Possible Solutions

There are numerous libraries that handle large numbers and high precision floating point numbers.

Falk Tandetzky
  • 5,226
  • 2
  • 15
  • 27