英文:
NSIS round disk size to nearest decimal place
问题
以下代码返回系统驱动器的大小(以GB为单位):
```nsi
!include logiclib.nsh
section
system::call 'kernel32::GetDiskFreeSpaceEx(t"$windir", *l.r0, *l, *l)'
size:
${if} $0 u> 1024
system::int64op $0 / 1024
pop $0
goto size
${endif}
detailprint $0
sectionend
如何将大小四舍五入到最接近的1或2个小数位,就像在内置目录页面中看到的那样?我尝试了intop
但它只返回0
。我不理解Math::Script
插件,它是否可以使用?
<details>
<summary>英文:</summary>
The following code returns the size of the system drive in GB:
```nsi
!include logiclib.nsh
section
system::call 'kernel32::GetDiskFreeSpaceEx(t"$windir", *l.r0, *l, *l)'
size:
${if} $0 u> 1024
system::int64op $0 / 1024
pop $0
goto size
${endif}
detailprint $0
sectionend
How do i get the size rounded to the nearest 1 or 2 decimal places, as seen using the built-in directory page? i tried intop
but it just returns 0
. i don't understand the Math::Script
plug-in, if it can be used
答案1
得分: 0
这似乎更像是一个数学问题而不是一个NSIS问题,但这里有一个简单的解决方案:
!include logiclib.nsh
Section
System::Call 'KERNEL32::GetDiskFreeSpaceEx(t"$windir", *l.r0, *l, *l)'
StrCpy $1 00
size:
StrCpy $1 $1 2 ; 一个简单的“四舍五入”方式
${If} $0 U> 1024
System::Int64Op $0 % 1024
Pop $1
System::Int64Op $0 / 1024
Pop $0
Goto size
${EndIf}
DetailPrint $0.$1
SectionEnd
英文:
This is perhaps more of a math question than a NSIS question but here is simple solution:
!include logiclib.nsh
Section
System::Call 'KERNEL32::GetDiskFreeSpaceEx(t"$windir", *l.r0, *l, *l)'
StrCpy $1 00
size:
StrCpy $1 $1 2 ; A lazy way to "round"
${If} $0 U> 1024
System::Int64op $0 % 1024
Pop $1
System::Int64op $0 / 1024
Pop $0
Goto size
${EndIf}
DetailPrint $0.$1
SectionEnd
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论