Search code examples
groovy

Using SimpleTemplateEngine and sending a string is scientific notation


Using Groovy-templates: 3.0.10,

The following processing is done

def WorkValue = 0.0003
def TestValue = WorkValue .toString() + " GB"

Templates:

Usage:${TestValue}

The output will be Usage:3.0E-4 GB. Is there anything I can do to make it display as 0.0003 GB?


Solution

  • For the code you have, WorkValue will have type BigDecimal and should output as you are wanting. If WorkValue has type float or double, then it will output according to how you describe but you could get the output you want with:

    def TestValue = sprintf "%7.4f GB", WorkValue