Cast INumber to double and back #7069
-
I am creating a filter that I want to be able to filter array of However the internal state of the filter must have high precision using doubles. How can I design the filter that has ability to convert For example casting to double could be done as folllows.
But how would I be able to cast the filtering result from double to INumber? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Use |
Beta Was this translation helpful? Give feedback.
-
If you need high precision, you might also consider looking at the decimal data tight as it is better for high precision small numbers. |
Beta Was this translation helpful? Give feedback.
-
@TonyValenti Thanks, that is a good tip. Actually I made filter that can also filter array of bytes, so I did not want to keep the internal state of the filter in bytes. So now I can use double/decimal for the filter which has bytes input and output. |
Beta Was this translation helpful? Give feedback.
Use
double.CreateChecked(num)
orCreateSaturating
orCreateTruncating
depending on your needs.