Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Is there anyway to diplay the umbracoBytes value as MB instead of KB?
Just divide it by 1024, and round to the number of decimals you need.
here is a script i use...
<a href="{$docFile}" title="{$docName}" target="_blank"><xsl:value-of select="$docName"/></a> [ File Size: <xsl:value-of select="format-number(data[@alias='umbracoBytes'] div 1024,'#,###')"/>]
Here is the xslt extension helper we are using to print out the bytes nicely, in GB, MB, KB or bytes depending on the size
public static string GetReadableFileSizeViaBytes(long Bytes){ if (Bytes >= 1073741824) { Decimal size = Decimal.Divide(Bytes, 1073741824); return String.Format("{0:##.##} GB", size); } else if (Bytes >= 1048576) { Decimal size = Decimal.Divide(Bytes, 1048576); return String.Format("{0:##.#} MB", size); } else if (Bytes >= 1024) { Decimal size = Decimal.Divide(Bytes, 1024); return String.Format("{0:##} KB", size); } else if (Bytes > 0 & Bytes < 1024) { Decimal size = Bytes; return String.Format("{0:##.##} Bytes", size); } else { return "0 Bytes"; }}
This is the above as XSLT ;) Laurie
<xsl:variable name="size" select="data [@alias = 'umbracoBytes']" /> <xsl:variable name="sizeAndSuffix"> <xsl:choose> <xsl:when test="$size >= 1073741824"> <xsl:value-of select="format-number($size div 1073741824,'#,###')"/> <xsl:text>GB</xsl:text> </xsl:when> <xsl:when test="$size >= 1048576"> <xsl:value-of select="format-number($size div 1048576,'#,###')"/> <xsl:text>MB</xsl:text> </xsl:when> <xsl:when test="$size >= 1024"> <xsl:value-of select="format-number($size div 1024,'#,###')"/> <xsl:text>KB</xsl:text> </xsl:when> <xsl:when test="$size > 0 and $size < 1024"> <xsl:value-of select="format-number($size div 0,'#,###')"/> <xsl:text> Bytes</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>0 Bytes</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:variable>
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Display umbracoBytes as MB instead of KB
Is there anyway to diplay the umbracoBytes value as MB instead of KB?
Just divide it by 1024, and round to the number of decimals you need.
here is a script i use...
<a href="{$docFile}" title="{$docName}" target="_blank"><xsl:value-of select="$docName"/></a> [ File Size: <xsl:value-of select="format-number(data[@alias='umbracoBytes'] div 1024,'#,###')"/>]
Here is the xslt extension helper we are using to print out the bytes nicely, in GB, MB, KB or bytes depending on the size
This is the above as XSLT ;) Laurie
<xsl:variable name="size" select="data [@alias = 'umbracoBytes']" /> <xsl:variable name="sizeAndSuffix"> <xsl:choose> <xsl:when test="$size >= 1073741824"> <xsl:value-of select="format-number($size div 1073741824,'#,###')"/> <xsl:text>GB</xsl:text> </xsl:when> <xsl:when test="$size >= 1048576"> <xsl:value-of select="format-number($size div 1048576,'#,###')"/> <xsl:text>MB</xsl:text> </xsl:when> <xsl:when test="$size >= 1024"> <xsl:value-of select="format-number($size div 1024,'#,###')"/> <xsl:text>KB</xsl:text> </xsl:when> <xsl:when test="$size > 0 and $size < 1024"> <xsl:value-of select="format-number($size div 0,'#,###')"/> <xsl:text> Bytes</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>0 Bytes</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:variable>
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.