ques-U8ThNh43

Search A2Z 24

Question : How to display valid size from given file size value ?

I have list of file and there size,which is getting from server

Example :

1. Name : xyz.png  Size : 1048576

2. Name pqr.jpg Size 12300

etc.

I need output like 

1. Name : xyz.png  Size : 1.0 MB

2. Name pqr.jpg Size 12.0 KB

 

 

 

 

asked June 30, 2015

1 Answers

Dispalying 1 to 1 of 1 |

In Javascript you can write a function and call that function to get valid size:

 
function getFileSize(fileSize) {
    var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
    var i = 0;
    while(fileSize >= 1024) {
        fileSize /= 1024;
        ++i;
    }
    return fileSize.toFixed(1) + ' ' + units[i];
}
See comments (0) | Comment
Answered 2 Years ago
Dispalying 1 to 1 of 1 |

Write your Answer write code <pre class="brush: xml">---code---</pre>

Login as a member to access answering block !! click-here
loading...

Reveal Modal Goodness

This is a default modal in all its glory, but any of the styles here can easily be changed in the CSS.

This is just a simple modal with the default styles, but any type of content can live in here. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi quis sem vel enim eleifend tristique. Etiam tincidunt faucibus pharetra.

×