nVelocity - 尝试“大于”时出现模板问题小数性质的比较
我有一个简单的对象,它的属性之一是名为 Amount 的小数。当我尝试将此属性作为 nVelocity 模板的一部分进行比较时,比较总是失败。如果我将属性更改为 int 类型,则比较效果很好。我需要在模板中添加任何额外内容才能进行比较吗?
下面是上述模板的示例:
#foreach( $bet in $bets )
<li>
$bet.Date $bet.Race
#if($bet.Amount > 10)
<strong>$bet.Amount.ToString("c")</strong>
#else
$bet.Amount.ToString("c")
#end
</li>
#end
下面是 Bet 类:
public class Bet
{
public Bet(decimal amount, string race, DateTime date)
{
Amount = amount;
Race = race;
Date = date;
}
public decimal Amount { get; set; }
public string Race { get; set; }
public DateTime Date { get; set; }
}
任何帮助将不胜感激。
I have a simple object that has as one of it's properties a decimal named Amount. When I attempt a comparison on this property as part of an nVelocity template, the comparison always fails. If I change the property to be of type int the comparison works fine. Is there anything extra I need to add to the template for the comparison to work?
Below is a sample from the aforementioned template:
#foreach( $bet in $bets )
<li>
$bet.Date $bet.Race
#if($bet.Amount > 10)
<strong>$bet.Amount.ToString("c")</strong>
#else
$bet.Amount.ToString("c")
#end
</li>
#end
Below is the Bet class:
public class Bet
{
public Bet(decimal amount, string race, DateTime date)
{
Amount = amount;
Race = race;
Date = date;
}
public decimal Amount { get; set; }
public string Race { get; set; }
public DateTime Date { get; set; }
}
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我测试了这个并且它有效。看来这是一个错误,在最新版本的 NVelocity(撰写本文时为 1.1)中不再存在。
I tested this and it worked. It seems this was a bug that isn't present any more in the latest release of NVelocity (1.1 as of this writing).
当然。
完整的 nVelocity 模板:
Bet 类:
程序:
预期输出测试:
实际产出测试:
如前所述,即使在第二个下注对象中,bet.Amount 的值为 15,nVelocity 模板中的比较 #if($bet.Amount > 10) 也会失败。如果 Amount 更改为 int 类型,比较按预期进行。
Sure.
The complete nVelocity template:
The Bet class:
Program:
Expected outputTest:
Actual outputTest:
As previously mentioned, the comparison #if($bet.Amount > 10) in the nVelocity template fails even though, in the second bet object, the value of bet.Amount is 15. If Amount is changed to be of type int, the comparison works as expected.