Angular 向下 2 轮
Angular 2 round down
{{(countValue/60) %60 | number:'2.0-0'}}
有没有办法向下舍入,上面的代码会给出“0.9”的结果是“1”我想要0谁能帮我
为此,您可以使用
Math.floor(yourValue);
或者如果你想使用自定义管道,请参考下面的代码
// round.pipe.ts
import {Pipe, PipeTransform} from "@angular/core";
@Pipe({name: 'round'})
export class RoundPipe implements PipeTransform {
/**
*
* @param value
* @returns {number}
*/
transform(value: number): number {
return Math.floor(value);
}
}
将其导入您的模块
// app.module.ts
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
routing
],
declarations: [
AppComponent,
RoundPipe
],
providers: [
BaseRequestOptions
],
bootstrap: [AppComponent]
})
在你的 html,
<!--your html -->
<span>{{(countValue/60) %60 | round }}</span>
{{(countValue/60) %60 | number:'2.0-0'}}
有没有办法向下舍入,上面的代码会给出“0.9”的结果是“1”我想要0谁能帮我
为此,您可以使用
Math.floor(yourValue);
或者如果你想使用自定义管道,请参考下面的代码
// round.pipe.ts
import {Pipe, PipeTransform} from "@angular/core";
@Pipe({name: 'round'})
export class RoundPipe implements PipeTransform {
/**
*
* @param value
* @returns {number}
*/
transform(value: number): number {
return Math.floor(value);
}
}
将其导入您的模块
// app.module.ts
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
routing
],
declarations: [
AppComponent,
RoundPipe
],
providers: [
BaseRequestOptions
],
bootstrap: [AppComponent]
})
在你的 html,
<!--your html -->
<span>{{(countValue/60) %60 | round }}</span>