Skip to content

Instantly share code, notes, and snippets.

@kenpb
Last active July 11, 2018 15:01
Show Gist options
  • Save kenpb/c10f9bec001559c75c26115eb27a9f04 to your computer and use it in GitHub Desktop.
Save kenpb/c10f9bec001559c75c26115eb27a9f04 to your computer and use it in GitHub Desktop.
A `round number` pipe for Angular from Bastien Donjon's blog, please check http://blog.bastien-donjon.fr/round-number-angular-2-pipe/
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
routing
],
declarations: [
AppComponent,
RoundPipe
],
providers: [
BaseRequestOptions
],
bootstrap: [AppComponent]
})
<span>{{ yournumber | round }}</span>
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment