Database Template Formulas & Formatting

This post was last updated for 359 days ago, and the information may already be changed

Can someone direct me on how to correctly get a percentage from values in a database? Here is my current function under the 'Template' column:

.action{ divf .Available .Limit }

Available represents one category and Limit represents another category. It produces the correct answer (a decimal result). When I try the following to get percentage:.

action{ divf .Available .Limit | mul 100 }

it results in 0. If I replace the fields Available and Limit with actual numbers, the result will generate a correct answer.

Can someone tell me what I'm doing wrong or provide me with the correct way to get an actual percentage from 2 fields?

Also, how do I format the number of decimal points in a 'Template' column? I've tried researching both answers and I'm not having much luck.

UPDATE: After formatting the following by adding an 'f' after 'mul'

.action{ divf .Available .Limit | mulf 100 }

I was able to get the percentage value correctly. Now, I still need assistance with formatting the number of decimal points.

UPDATE 2: I was able to format the decimal points by doing the following:

.action{FormatFloat "##.##" (divf .Available .Limit | mulf 100)}

where "##" is how you want the result formatted. I hope this post is useful for others!

    4 Operate
    mindarchr updated this article at 2025-04-15 12:05:35
    mindarchr updated this article at 2025-04-15 12:04:49
    mindarchr updated this article at 2025-04-15 12:02:57
    mindarchr updated this article at 2025-04-14 13:37:54

    Related articles

    Welcome to here!

    Here we can learn from each other how to use SiYuan, give feedback and suggestions, and build SiYuan together.

    Signup About
    Please input reply content ...