How do you convert a decimal with a unit of measure to a float with the same unit?

I can't figure out how to convert a decimal with a unit of measure to a float with a unit of measure.

I experimented with code similar to:

let toFloat (value: decimal<'T>) = let value = float (value / LanguagePrimitives.GenericOne<decimal<'T>>) value * LanguagePrimitives.GenericOne<float<'T>> 

This method creates a decimal → float signature, which I don't want. I am trying to create a function like decimal <'T> → float <' T>.

Is it possible to create such a function? If so, what does it look like?

+4
source share
1 answer

I looked it up at http://www.tryfsharp.org and it seems like this should work:

 let toFloat (value: decimal<'T>) = LanguagePrimitives.FloatWithMeasure<'T>(float (decimal value)) 
+5
source

Source: https://habr.com/ru/post/1489949/