I'm trying to check if a number inputed has over 8 decimal places and if it does then I want to round it back down to 8 decimal places. However, when I input the number 1.234001, it automatically rounds it to 8 decimal places. (1.234001 / 0.00000001) % 1 = 0 so I'm not sure why its rounding it. Here's my code

```var SAT = 0.00000001;
if(!isNaN(input.value) && ((input.value / SAT) % 1 != 0)) {
input.value = parseFloat(input.value).toFixed(8);
console.log(6);
}```
Sep 12, 2018 1,284 views

## 1 answer to this question.

Try it in this way:

```function nrOfDecimals(number) {
var match = (''+number).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?\$/);
if (!match) { return 0; }

var decimals =  Math.max(0,
(match[1] ? match[1].length : 0)
// Correct the notation.
- (match[2] ? +match[2] : 0));

if(decimals > 8){
//if decimal are more then 8
number = parseFloat(number).toFixed(8);
}
return number;
}```
• 29,350 points

## How to run a Javascript in truffle console?

There are two ways to do this. You ...READ MORE

## How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

+1 vote

## Can I include real world data in a smart contract? If so, how?

You cant access/embed real world data using ...READ MORE

+1 vote

## How efficient is Ethereum in regard to its TPS??

TPS means transactions processing at any given ...READ MORE

+1 vote

## How to perform a simple 1-to-1 Bitcoin Transaction with Bitcore?

What is the argument utxos int the ...READ MORE

+1 vote

## Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

## Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE