Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does terraform support math rounding?

Is it possible to round an integer value in terraform string interpolations?

like image 844
Ethan Stein Avatar asked Jan 26 '26 11:01

Ethan Stein


1 Answers

There is another native terraform way of doing this, not sure if it's new but I just found it and thought I should add it here for reference:

format("%.2f", data.aws_ec2_spot_price.emr.spot_price)

This will return my spot_price as a 2 digit number, this uses the width operator in the format function

A width modifier can be included with an optional decimal number immediately preceding the verb letter, to specify how many characters will be used to represent the value. Precision can be specified after the (optional) width with a period (.) followed by a decimal number. If width or precision are omitted then default values are selected based on the given value. For example:

Sequence Result

  • %f Default width and precision.
  • %9f Width 9, default precision.
  • %.2f Default width, precision 2.
  • %9.2f Width 9, precision 2.
like image 53
Rumbles Avatar answered Jan 29 '26 03:01

Rumbles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!