Proektsoftbg / Calcpad

Free and open source software for mathematical and engineering calculations.
https://calcpad.eu
MIT License
313 stars 38 forks source link

Idea: include financial units - number formatting options #288

Open murilo-s opened 2 months ago

murilo-s commented 2 months ago

Quick suggestion:

Include some basic financial units, like the dollar sign $, day, month, year, apy.

Also, make it possible to change number formatting, to show x.xxx,xx or $x.xxx,xx for example

Thanks.

Proektsoftbg commented 2 months ago

Hi! Thank you for your suggestion. Currently, custom number formatting is not implemented in Calcpad and this is something we can improve in future. However, there is some options to use JavaScript to format numbers. I will post some code later.

Proektsoftbg commented 2 months ago

Hi!

Here is some useful example how to format a table with prices as currency: image

The source code is the following:

price_conc = 12001.34567
price_steel = 52005.34567
#val
'<table class="bordered">
'<thead>
'<tr><th>Item</th><th>Price, USD</th></tr>
'</thead>
'<tbody>
'<tr><td>Concrete</td><td class="usd">'price_conc'</td></tr>
'<tr><td>Steel</td><td class="usd">'price_steel'</td></tr>
'</tbody>
'</table>
#equ
'<script>var USDollar = new Intl.NumberFormat("en-US", {style: "currency",currency: "USD",}); $(".usd").each(function(){$(this).text(USDollar.format(parseFloat($(this).text())));});</script>

The key is to add this little script at the end and class="usd" to the html element that encloses the currency value. This works only in #val section where only numbers are present in the output and not variables and equations.