Convert System.Decimal from C# .NET to double

6 vues (au cours des 30 derniers jours)
Christopher Saltonstall
Christopher Saltonstall le 3 Août 2023
Commenté : Walter Roberson le 30 Déc 2024
I am communicating with a Thorlabs DC servo controller via .NET. When I query the motor position it returns the value in system.decimal format. I found some documentation that briefly mentions this format but doesn't explain how to convert it to a usable numerical value.
How can I can I convert this to something usable?
The returned postion variable is attached.

Réponse acceptée

Christopher Saltonstall
Christopher Saltonstall le 3 Août 2023
load 'pos.mat'
import System.*
methodsview('System.Decimal')
System.Decimal.ToDouble(pos)
  4 commentaires
Walter Roberson
Walter Roberson le 29 Sep 2023
Notes:
This can only work on Windows
You might need to do the import before the load, so that the class is defined at the time of the load()
Valeriy
Valeriy le 3 Oct 2023
OK, I see it, thank you, it is attached

Connectez-vous pour commenter.

Plus de réponses (1)

Grace Kepler
Grace Kepler le 30 Déc 2024
Here is an example without using "pos.mat".
>> xdecimal = System.Decimal(100.1)
xdecimal =
Decimal with properties:
Scale: 1
Zero: [1×1 System.Decimal]
One: [1×1 System.Decimal]
MinusOne: [1×1 System.Decimal]
MaxValue: [1×1 System.Decimal]
MinValue: [1×1 System.Decimal]
>> xdouble = System.Decimal.ToDouble(xdec)
xdouble =
100.1000
  1 commentaire
Walter Roberson
Walter Roberson le 30 Déc 2024
Note that System.Decimal is only available on MS Windows.

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Compiler SDK dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by