Count in binary bytes and remove i18 from file size format service
This commit is contained in:
parent
88145c5934
commit
6a00854189
4 changed files with 13 additions and 11 deletions
Binary file not shown.
|
@ -1,15 +1,15 @@
|
|||
const fileSizeFormat = (num, t) => {
|
||||
const fileSizeFormat = (num) => {
|
||||
var exponent
|
||||
var unit
|
||||
var units = [t('file_size_units.B'), t('file_size_units.KB'), t('file_size_units.MB'), t('file_size_units.GB'), t('file_size_units.TB')]
|
||||
var units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
||||
if (num < 1) {
|
||||
return num + ' ' + units[0]
|
||||
}
|
||||
|
||||
exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1)
|
||||
num = (num / Math.pow(1000, exponent)).toFixed(2) * 1
|
||||
exponent = Math.min(Math.floor(Math.log(num) / Math.log(1024)), units.length - 1)
|
||||
num = (num / Math.pow(1024, exponent)).toFixed(2) * 1
|
||||
unit = units[exponent]
|
||||
return num + ' ' + unit
|
||||
return {num: num, unit: unit}
|
||||
}
|
||||
const fileSizeFormatService = {
|
||||
fileSizeFormat
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue