Open In App

Angular PrimeNG Form InputNumber Decimal Mode Component

Last Updated : 31 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will learn how to use the Form InputNumber Decimal Mode Component in Angular PrimeNG. We will also learn about the properties, along with their syntaxes that will be used in the code.

The InputNumber Component allows a user to input content as a numerical value. When no additional configuration is present, the default value of the mode property, “decimal” restricts input to the integers format that is configured using this property.

Syntax:

<p-inputNumber
   placeholder="..."
   mode="decimal"
   [minFractionDigits]="..." 
   [maxFractionDigits]="...">
</p-inputNumber>

 

Angular PrimeNG Form InputNumber Decimal Mode Component Properties:

  • placeholder: It is used to set the advisory information to display on input. It is of string data type, the default value is null.
  • mode: It is used to define the behavior of the component, valid values are “decimal” and “currency”. It is of string data type, the default value is decimal.
  • minFractionDigits: It is used to set the minimum number of fraction digits to use. It is of number data type, the default value is null.
  • maxFractionDigits: It is used to set the maximum number of fraction digits to use. It is of number data type, the default value is null.

Creating Angular application & module installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: The project structure will look like the following image:

 

  • Run the below command to see the output:
ng serve --save

Example 1: In the below code, we will be seeing the demonstration of the Angular PrimeNG Form InputNumber Decimal Mode Component.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>
    Angular PrimeNG Form InputNumber 
    Decimal Component
</h5>
<p-inputNumber placeholder="Input any number"
               mode="decimal">
</p-inputNumber>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent { }


  • app.module.ts:

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { InputNumberModule }
     from 'primeng/inputnumber';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        InputNumberModule,
        FormsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }


Output:

 

Example 2: Below is another code example that demonstrates the Angular PrimeNG Form InputNumber Decimal Mode Component using minFractionDigits and maxFractionDigits properties.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>
    Angular PrimeNG Form InputNumber 
    Decimal Component
</h5>
<p-inputNumber placeholder="Input any number"
               mode="decimal"
               [minFractionDigits]="1" 
               [maxFractionDigits]="3">
</p-inputNumber>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent { }


  • app.module.ts:

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { InputNumberModule }
     from 'primeng/inputnumber';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        InputNumberModule,
        FormsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }


Output:

 

Reference: https://primefaces.org/primeng/inputnumber



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads