We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to round numbers in Aspose


I’m trying to create a report using Aspose using some custom attributes like TotalSum (i define them myself)

There is a construction I use:

<<var [grammar = new GrammarScriptlet()]>>
<<[base.TotalSum]:"#,###.00">> <<[grammar.getMoney(new BigDecimal(base.TotalSum))]>>

the expected result is smth like that
1 000.20 (one thousand dollars twenty cents)

but sometime it gives the result like this:
1 000.20 (one thousand dollars nineteen cents)

I investigated this and the reason is that <<[base.TotalSum]:"#,###.00">> rounds the number and <<[grammar.getMoney(new BigDecimal(base.TotalSum))]>> doesn’t

I need these two atributes to match perfectly, if it’s 0.20 cents then it should be twenty cents, not nineteen.

How can I round a number in Aspose? Before using a getMoney function.

I searched here https://docs.aspose.com/words/net/appendix-a-enumeration-extension-methods/ and got nothing.

Please help. Thank you.

If you are using BigDecimal class in your template document, you can round your value in the way, shown bellow:

(new BigDecimal(1000.1999)).setScale(2, RoundingMode.HALF_UP);

If you still facing the problem, please share sample code you used to get an output document. We will then provide you code example and/or updated template document needed to get desired result according to your requirement.