I am currently involved in a project that requires precise number calculations, as well as a visually appealing display of these numbers to the users.
Below is the HTML code snippet:
<span> {{ getTotalStocksValue() }} %</span>
<button data-ng-click="redistribute()">Redistribute</button>
<form action="">
<input type="text" data-numeric-input-directive data-ng-repeat="stock in stocks" data-ng-model="stock.value">
</form>
We showcase various stocks with their values, allowing manual changes to each stock's value. The total value of all stocks is displayed in the span using the getTotalStocksValue()
function.
The "Redistribute" button distributes the stock values so that the total value equals 100%.
The task at hand is to show the stock values in the inputs rounded to 2 decimal places, while also retaining the values in 4 decimal places for more accurate calculations in the getTotalStocksValue
function.
For instance, if there are 3 stocks and each has a value of 33.33, the total would be 99.99. However, if a user updates the stock values to 33.3333 each, the total should automatically round up to 100 from 99.9999.
I'm unsure if Angular allows for such implementation.
My only thought is to display the stock values in the inputs as 4 decimal places and additionally exhibit them in a span or div as 2 decimal places.
Any suggestions or recommendations?