<p>In helm, there are Math functions <a href="https://helm.sh/docs/chart_template_guide/function_list/#math-functions" rel="nofollow noreferrer">https://helm.sh/docs/chart_template_guide/function_list/#math-functions</a> and they have a <code>div</code> function which divides integer! but is there any way to get a decimal result out of division?</p>
<p>I need to get a unit interval out of the percentage.</p>
<p>So if the value is 90 I need to get 0.9, if it is 2 I need 0.02.</p>
<p>Thanks</p>

HSLM
<p>Unfortunately there are no functions available in Helm templates which support floating point division.</p>
<p>Easiest would be to register a custom function which does the conversion and division.</p>
<p>If you can't register your custom functions, there is still a way to do this with what's available in Help templates.</p>
<p>You may construct a string that contains the floating point representation of the expected result, and use the <code>float64</code> Helm template function to parse that string into a <code>float64</code> value.</p>
<p>Here's how it may look like:</p>
<pre><code>{{ printf &quot;%d.%02d&quot; (div . 100) (mod . 100) | float64 }}
</code></pre>
<p>If the percent is <code>100</code>, the first digit will be <code>1</code>, <code>0</code> otherwise. Then follows a dot and the 2-digit value of the percent, so using this format string, you'll get the floating point representation. Passing this to the <code>float64</code> function, it'll parse it and return it as a <code>float64</code> value.</p>
<p>Testing it:</p>
<pre><code>    t := template.Must(template.New(&quot;&quot;).Funcs(template.FuncMap{
        &quot;div&quot;:     func(a, b int) int { return a / b },
        &quot;mod&quot;:     func(a, b int) int { return a % b },
        &quot;float64&quot;: func(s string) (float64, error) { return strconv.ParseFloat(s, 64) },
    }).Parse(`{{range .}}{{ printf &quot;%d.%02d&quot; (div . 100) (mod . 100) | float64 }}
{{end}}`))

    if err := t.Execute(os.Stdout, []int{0, 2, 90, 100}); err != nil {
        panic(err)
    }
</code></pre>
<p>Output (try it on the Go Playground):</p>
<pre><code>0
0.02
0.9
1
</code></pre>
