Last active
July 11, 2018 15:01
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NgModule({ | |
imports: [ | |
BrowserModule, | |
FormsModule, | |
HttpModule, | |
routing | |
], | |
declarations: [ | |
AppComponent, | |
RoundPipe | |
], | |
providers: [ | |
BaseRequestOptions | |
], | |
bootstrap: [AppComponent] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span>{{ yournumber | round }}</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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