我想创建一个指令,它将在十进制之后舍入两位数值。
例如:
10.456456应为10.46
10.3633应为10.34
这是我到目前为止所尝试过的,但它无效。
if (Globals.ThisAddIn.Application.Inspectors.Count > 0)
{
Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
if (inspector.CurrentItem is Outlook.MailItem)
{
Outlook.MailItem mail = (Outlook.MailItem)inspector.CurrentItem;
string pidNameContentType = mail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/content-type/0x0000001F");
}
}
HTML:
marineQuote.directive('roundConverter2', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elem, attrs, ngModelCtrl) {
function roundNumber(input, places) {
if (isNaN(input)) return input;
var factor = "1" + Array(+(places > 0 && places + 1)).join("0");
return Math.round(input * factor) / factor;
}
ngModelCtrl.$parsers.push(roundNumber);
}
};
});
答案 0 :(得分:1)
试试这个:
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elem, attrs, ngModelCtrl) {
function roundNumber(input, places) {
if (isNaN(input)) return input;
return parseFloat(input).toFixed(2);
}
ngModelCtrl.$parsers.push(roundNumber);
}
};
希望这对你有用。