Introduction:
Here I will explain how to convert size bytes to kb, mb, gb or tb in AngularJS or JavaScript or jQuery. By "Math" formulas we can convert size bytes to kb, mb, gb or tb in AngularJS or jQuery or JavaScript.
Description:
In previous articles I explained Angularjs convert number to currency format, Angularjs get dropdownlist selected value, Angularjs convert text to uppercase while typing, Angularjs refresh div for every 1 second using interval mode, 5 + Angularjs Gridview and table plugin examples with demos and many articles relating to AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to convert size bytes to kb, mb, gb or tb using AngularJS or JavaScript or jQuery.
In previous articles I explained Angularjs convert number to currency format, Angularjs get dropdownlist selected value, Angularjs convert text to uppercase while typing, Angularjs refresh div for every 1 second using interval mode, 5 + Angularjs Gridview and table plugin examples with demos and many articles relating to AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to convert size bytes to kb, mb, gb or tb using AngularJS or JavaScript or jQuery.
|
If you want to check it in complete example you need to
write the code like as shown below
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Convert size (Bytes) to
KB, MB, GB, TB in Angularjs</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var myApp =
angular.module('sampleapp', [])
myApp.controller("expressionController",
function ($scope) {
$scope.fnconvertsize = function ()
{
var bytessize =
$scope.sizeinbytes;
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytessize == 0)
$scope.convertedsize= '0 Byte';
var i =
parseInt(Math.floor(Math.log(bytessize) / Math.log(1024)));
$scope.convertedsize = Math.round(bytessize / Math.pow(1024, i), 2)
+ ' ' + sizes[i];
}
});
</script>
</head>
<body>
<form id="form1">
<div data-ng-app="sampleapp"
data-ng-controller="expressionController">
<input type="number"
ng-model="sizeinbytes">
<br/><br/>
<input type="button"
ng-click="fnconvertsize()"
value="Convert
Size" /><br/><br/>
Converted Size : <span id="cdefault">{{convertedsize}}</span><br/>
</div>
</form>
</body>
</html>
|
Live
Demo
For
live demo try to enter values in textbox and click button to get conversion size
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.