Hi,
I’ve got a template which does a few calculations on memory (to set up hugepages etc), and I need to round the result but I’m not sure how to.
`
This is the expression:
“{{ (((60/100)* ansible_memtotal_mb)*1024)/2048 }}”
`
I usually end up with a decimal, but I need to get rid of the decimal:
`
Result: 600.6 and I’d like to round that to 601
Result: 1201.1 should be rounded to 1201
`
etc
Any idea on how to do that?
Thanks!
/M
sivel
(sivel)
2
You are looking for the aptly named “round” filter:
http://jinja.pocoo.org/docs/dev/templates/#round
some_val|round
Doh!
Awesome, that did the trick.
someval |round|int
Thanks!
/M
Have a look at the '//' operator :
http://jinja.pocoo.org/docs/dev/templates/#math
- it rounds down, but saves the extra step.
Hi,
Please take a look at this example:
innodb_buffer_pool_size = {{
(0.85*ansible_memtotal_mb/1024)|int }}G
As a result I get:
innodb_buffer_pool_size = 120G
oravirt
6
Hi,
Yeah it’s already sorted, but thanks!
/M