[英]Brokered Windows Runtime Component - System.Decimal
I am receiving a compiler error: 我收到编译器错误:
"Method xxx has parameter value of type "System.Decimal". "System.Decimal" is not a valid Windows Runtime must return only Windows Runtime types." “方法xxx的参数值类型为“ System.Decimal”。“ System.Decimal”不是有效的Windows运行时,必须仅返回Windows Runtime类型。
Is there anyway I can use a decimal? 无论如何,我可以使用小数吗? or should I just store the value as cents in an integer?
还是应该将值存储为整数?
I found the easiest solution was to store it as cents in an integer. 我发现最简单的解决方案是将其存储为整数。
I believe this may not work for all the currencies in the world but I am only concerned with dollars so its not an issue in this particular scenario. 我认为这可能不适用于世界上所有的货币,但我只担心美元,因此在这种特定情况下这不是问题。
An alternative is to implement a "money" pattern - http://martinfowler.com/eaaCatalog/money.html 另一种方法是实现“金钱”模式-http://martinfowler.com/eaaCatalog/money.html
Actually, I found the easiest way is to use double
for the return values and parameters of my WinRT component. 实际上,我发现最简单的方法是对WinRT组件的返回值和参数使用
double
。
This is what I have in my C# Class Library 这就是我的C#类库中的内容
public static double Round(double value, int digits)
{
// do stuff
}
This is the code of a C# Windows Runtime Portable Class Library I created as a wrapper to be called from my JavaScript code 这是我创建的C#Windows运行时可移植类库的代码,作为包装程序,可从我的JavaScript代码中调用
public static double Round(double val, int digits)
{
return MyCSharpClassLib.Class.Round(val, digits);
}
And from my JavaScript project, this is what I call 在我的JavaScript项目中,这就是我所说的
var round = WindowsRuntimeWrapper.Class1.round(3.1415926549, 3);
And it works just fine! 而且效果很好!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.