Search results

Number Formats

You can format the value of NumericTextBox using format property. The value will be displayed in the specified format when the component is in focused out state. The format string supports both the standard numeric format string and custom numeric format string.

Standard formats

From the standard numeric formats, you can use the numeric related format specifiers such as n,p and c in the NumericTextBox component. By using these format specifiers, you can achieve the percentage and currency textbox behavior also.

The below example demonstrates percentage and currency formats.

Source
Preview
index.tsx
index.html
import * as React from "react";
import * as ReactDOM from "react-dom";
import { NumericTextBoxComponent } from '@syncfusion/ej2-react-inputs';

// initializes NumericTextBox component
// sets percentage with 2 numbers of decimal places format
ReactDOM.render(<NumericTextBoxComponent format='p2' value={0.5} min={0} max={1} step={0.01} placeholder='Percentage format' floatLabelType='Auto' >
</NumericTextBoxComponent>,document.getElementById('numericContainer1'));

// initializes NumericTextBox component
// sets currency with 2 numbers of decimal places format
ReactDOM.render(<NumericTextBoxComponent format='c2' value={10} placeholder='Currency format' floatLabelType='Auto' >
</NumericTextBoxComponent>,document.getElementById('numericContainer2'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 React NumericTextBox</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="React NumericTextBox Component" />
    <meta name="author" content="Syncfusion" />
    <link href="styles.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div class='wrap'>
        <div id='numericContainer1'>
            <div id='loader'>Loading....</div>
        </div>
    </div>
    <div class='wrap'>
        <div id='numericContainer2'>
        </div>
    </div>
</body>

</html>

Custom formats

From the custom numeric format string, you can provide any custom format by combining one or more custom specifiers.

The below examples demonstrate format the value by using currency format string # and 0.

Source
Preview
index.tsx
index.html
import * as React from "react";
import * as ReactDOM from "react-dom";
import { NumericTextBoxComponent } from '@syncfusion/ej2-react-inputs';

// initializes NumericTextBox component
// sets the format using custom format string `#`
ReactDOM.render(<NumericTextBoxComponent format='###.##' value={10} placeholder='Custom format string #' floatLabelType='Auto'  >
</NumericTextBoxComponent>,document.getElementById('numericContainer1'));

// initializes NumericTextBox component
// sets the format using custom format string `0`
ReactDOM.render(<NumericTextBoxComponent format='000.00' value={10} placeholder='Custom format string 0' floatLabelType='Auto' >
</NumericTextBoxComponent>,document.getElementById('numericContainer2'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 React NumericTextBox</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="React NumericTextBox Component" />
    <meta name="author" content="Syncfusion" />
    <link href="styles.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div class='wrap'>
        <div id='numericContainer1'>
            <div id='loader'>Loading....</div>
        </div>
    </div>
    <div class='wrap'>
        <div id='numericContainer2'>
        </div>
    </div>
</body>

</html>