Asked by:
datatype "Decimal" in VB.Net is 32bit or 64bit?
Question

Module Module1 Sub Main() Dim pi As Decimal = 3D System.Console.WriteLine("Calculation in Progress...") For i As Integer = 1 To 10000000 If i Mod 2 = 1 Then pi = pi + (4 / ((2D * i) * ((2D * i) + 1) * ((2D * i) + 2))) Else pi = pi  (4 / ((2D * i) * ((2D * i) + 1) * ((2D * i) + 2))) End If Next Console.WriteLine("Result is {0}", pi.ToString) Console.WriteLine("Press any Key to Continue...") System.Console.ReadKey() End Sub End Module
code above is program to calculate number of Pi.
I know datatype of "Decimal" will is occupy 16 byte memory allocation. but I wish to know data will be store as 64bit data in 64bit program or 32bit data in 64bit program? or 16bit instead?
All replies

16 bytes means 128 bits:
MsgBox(Marshal.SizeOf(Of Decimal) * 8) ' Shows 128
You can check it in various environment.
In Compile tab of Project Properties you can find the “Prefer 32bit” option and perform experiments. This should not affect the size of Decimal.
 Edited by Viorel_MVP Friday, February 14, 2020 5:06 PM

Here is an article that discusses the Decimal data type.
https://www.w3computing.com/vb2008/vbdecimaldatatype/
The values are 16 bytes which, as Viorel said, is 128 bits. The numbers can store up to 28 decimal digits, which means it's using about 91 bits for the mantissa. (There are 3.232 bits per decimal digit.)
You need to understand that the Decimal data type is not directly supported in the hardware, like integers and floats. All of the math operations are simulated in software. That means math like you are doing is very slow. Also, the algorithm you are using is itself very slow. Even after 10,000,000 operations, like you have here, you will still only have about 20 digits of pi. You can tell that because you are adding or subtracting basically 1/(n^3) during the nth iteration. 10,000,000 is 10^7, and 10^7 cubed is 10^21. To get 28 decimal digits, you'd need to run at least 2,000,000,000 loops.
Tim Roberts  Driver MVP Emeritus  Providenza & Boekelheide, Inc.

Even after 10,000,000 operations, like you have here, you will still only have about 20 digits of pi. You can tell that because you are adding or subtracting basically 1/(n^3) during the nth iteration. 10,000,000 is 10^7, and 10^7 cubed is 10^21. To get 28 decimal digits, you'd need to run at least 2,000,000,000 loops.
Calculation in Progress...
Result is 3.1415926535897932384623932776
 Wayne