Is there a way to format the Asset Size variable to Mb, Kb, etc.? I'm trying to display the file size of a file uploaded in Assets. I can get it to display the number of bytes in the file. https://craftcms.com/docs/templating/craft.assets#size

Is there a way to format that number to Mb's?
This should do it:

{% set bytes = asset.size %}
{% set kiloBytes = (bytes / 1024)|round(2) %}
{% set megaBytes = (kiloBytes / 1024)|round(2) %}

bytes = {{ bytes }}
kiloBytes = {{ kiloBytes }}
megaBytes = {{ megaBytes }}


You can look at Twig's number_format filter if you want to get fancy with how to display the numbers.