Add file size formating
This commit is contained in:
parent
4fde987e34
commit
c69a8dc197
4 changed files with 27 additions and 1 deletions
BIN
src/services/file_size_format/.file_size_format.js.swp
Normal file
BIN
src/services/file_size_format/.file_size_format.js.swp
Normal file
Binary file not shown.
17
src/services/file_size_format/file_size_format.js
Normal file
17
src/services/file_size_format/file_size_format.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
const fileSizeFormat = (num, t) => {
|
||||
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')]
|
||||
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
|
||||
unit = units[exponent]
|
||||
return num + ' ' + unit
|
||||
}
|
||||
const fileSizeFormatService = {
|
||||
fileSizeFormat
|
||||
}
|
||||
export default fileSizeFormatService
|
Loading…
Add table
Add a link
Reference in a new issue