I'm doing a proof of concept that involves porting some Pascal code over to C#.
The code involves financial calculations, so most of the fields are currency based (though not all).
All of the numeric fields are defined as Real data type in Pascal.
Because the code deals with mainly currency fields, I had decided to use the decimal data type in C#.
I have come across a piece of code that seems to do a "power of" in Pascal (it is a double asterisk). It does not round the results of the power call straight away (it may do later I'm not 100% sure as there are thousands of lines of code).
Out of the box in C# the Math.Pow method only accepts double data types.
I'm wondering as an overall concept/rule of thumb - should I be using double instead of decimal to begin with if trying to port Pascal Real data types over to C#?
Or what would people recommend?
Realis either 32 or 64 bit floating point value depending on the system. So if you want to have the closest C# implementation, pick eitherfloatordoubleaccordingly. You can useMath.Powwith both.doubleandfloatare not suitable for financial calculations as they have some inaccuracy which can compound over multiple operations. See What is the best data type to use for money in C#?Math.Powondecimal, so I thought I'd be nce and point to a duplicate.