Home > Mobile >  Is there any way I can keep the type of a percentage as number after doing number formatting?
Is there any way I can keep the type of a percentage as number after doing number formatting?

Time:05-20

I changed a number lets say (150) to 150.00% using number formatting. Now this is the way I want to display the number with the percentage sign. But I want it to be of number type but it is of type string. Is there any way I can do this?

CodePudding user response:

No. A number is just a number, it has nothing to indicate what you're using that number for — a percentage, a currency amount, the number of angels that can dance on the head of a pin, etc. It's just a number.

You'll need to store two pieces of information: The number, and the fact it's a percentage.

CodePudding user response:

Hi if you want to keep the number type in input tag then its good to go with bootstrap input-group-append/prepend to add % sign. this will keep the input with number formet and you will able to show % sign as well.

take a look on this demo.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Input group</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div >
  <h1>Bootstrap Input Group Example</h1>
  <p>This is demo about append and prepend using bootstrap</p> 
</div>
<div >
  <div >
    <span  id="basic-addon1">@</span>
  </div>
  <input type="text"  placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
</div>

<div >
  <input type="number"  placeholder="number" aria-label="Number" aria-describedby="basic-addon2">
  <div >
    <span  id="basic-addon2">%</span>
  </div>
</div>

<label for="basic-url">Your vanity URL</label>
<div >
  <div >
    <span  id="basic-addon3">https://example.com/users/</span>
  </div>
  <input type="text"  id="basic-url" aria-describedby="basic-addon3">
</div>

<div >
  <div >
    <span >$</span>
  </div>
  <input type="text"  aria-label="Amount (to the nearest dollar)">
  <div >
    <span >.00</span>
  </div>
</div>

<div >
  <div >
    <span >With textarea</span>
  </div>
  <textarea  aria-label="With textarea"></textarea>
</div>

</body>
</html>

  • Related