I took a look at it on http://www.tryfsharp.org and it seems that this should work:
let toFloat (value: decimal<'T>) =
LanguagePrimitives.FloatWithMeasure<'T>(float (decimal value))
Question
I cannot figure out how to convert a decimal with a unit of measure to a float with a unit of measure.
I have been experimenting with code similar to:
let toFloat (value: decimal<'T>) =
let value = float (value / LanguagePrimitives.GenericOne<decimal<'T>>)
value * LanguagePrimitives.GenericOne<float<'T>>
This method produces a signature of decimal -> float, which is not what I want. I'm trying to create a function of type decimal<'T> -> float<'T>.
Is it possible to create such a function? If so, what would it look like?
Solution
I took a look at it on http://www.tryfsharp.org and it seems that this should work:
let toFloat (value: decimal<'T>) =
LanguagePrimitives.FloatWithMeasure<'T>(float (decimal value))