Round number with Angular 2, pipe and Typescript
Written by Bastien Donjon, Posted in Javascript, typescript
// 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.round(value); } }
// app.module.ts @NgModule({ imports: [ BrowserModule, FormsModule, HttpModule, routing ], declarations: [ AppComponent, RoundPipe ], providers: [ BaseRequestOptions ], bootstrap: [AppComponent] })
<!-- exemple --> <span>{{ yournumber | round }}</span>
Builded with TypeScript 1.8 for Angular 2.RC5