javaScript Bytes to KB MB GB TB
JavaScript byte converting function demo
Add Byte and click convert
Byte :
<input type="number" id="byte" value="1024">
<button id="convert-byte">Convert</button>
<div id="preview-size"></div>
<script>
function byte_format(bytes) {
bytes = bytes.toString().replace(/[^0-9.]/g, '');
var sizes = ["B", "KB", "MB", "GB", "TB"];
bytes = parseInt(bytes);
if (bytes <= 0 || isNaN(bytes)) return "0 B";
var i = Math.floor(Math.log(bytes) / Math.log(1024));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}
document.getElementById("convert-byte").onclick = function(){
let byte = document.getElementById("byte").value;
let result = byte_format(byte);
document.getElementById("preview-size").innerHTML= result
}
</script>
Get text size in Byte KB
Add your text here click convert size:
<textarea id="text-val">Lorem ipsum dolor sit amet,....</textarea>
<button id="convert">Convert</button>
<div id="preview-size"></div>
<script>
function byte_format(bytes) {
bytes = bytes.toString().replace(/[^0-9.]/g, '');
var sizes = ["B", "KB", "MB", "GB", "TB"];
bytes = parseInt(bytes);
if (bytes <= 0 || isNaN(bytes)) return "0 B";
var i = Math.floor(Math.log(bytes) / Math.log(1024));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}
document.getElementById("convert").onclick = function(){
let text = document.getElementById("text-val").value;
var size = new Blob([text]).size;
let result = byte_format(size);
document.getElementById("preview-size").innerHTML= result
}
</script>
HTML CSS Rainbow TextHTML
Drop Down Select CountryHTML
CSS Button With IconCSS
Country flag imagesImage
SQL Country Names TableSQL
Bootstrap Forms BuilderBootstrap
PHP Get User DetailsPHP
JQuery Accordion Menu GeneratorJQuery
JavaScript Code DecompressorJavaScript
CSS Reflections GeneratorCSS
CSS Multiple Text ShadowCSS