
File size converter
Convert a data size between decimal and binary units.
Your inputs stay in your browser.
Method and assumptions
Method version 1.0.0 · Updated
Convert size
Formula: Size in bytes ÷ number of bytes in the target unit.
Mathematical conversions displayed to six decimal places.
- size
- Size
- fromUnit
- From
- toUnit
- To
Decimal units use powers of 1,000; binary units use powers of 1,024.
Calculate with code
These short examples use the same inputs and core calculation as this tool. Adapt validation and formatting to your application.
JavaScript
const bytes = 1_500_000;
console.log(bytes / 1_000_000); // 1.5 MB (decimal)TypeScript
const bytes = 1_500_000;
const megabytes: number = bytes / 1_000_000;
console.log(megabytes); // 1.5 MB (decimal)Python
print(1_500_000 / 1_000_000) # 1.5 MB (decimal)Java
System.out.println(1_500_000 / 1_000_000d); // 1.5 MB (decimal)C#
Console.WriteLine(1_500_000m / 1_000_000m); // 1.5 MB (decimal)