2/26/2023 0 Comments Convert gb to mb software![]() ![]() When want to apply precision and return only 2(or any given number) of digits after the dot: Another problem you will notice is the no. ![]() I feel this not a good programming approach. We can follow a ugly way like suffixing the number with a string “MB” and then divide it by 1GB (“245760MB”/1GB). Conversion like 245760/1GB treats 245760 as bytes and calculation will go wrong. This is because, from property name you know it is in MB but there is no easy way to make the shell understand that is in MB while doing the conversion. ![]() In that case, you need to convert the number to bytes and then convert back to your final required format. ![]() For example, VMware datastores will have a property which says CapacityinMB and the value will be integer. When you want to convert a value from other than bytes to KB/MB/TB/GB: It is easy to convert any format to other using PowerShell console but when it comes to writing scripts, we will have this problem. Ok, then where is the problem and why I am writing this post. If you have a number in bytes and want to convert it into MB or GB, it is as simple as typing 12345/1GB or 12345/1MB in PowerShell prompt or script. We all know that size conversion in PowerShell is pretty straightforward. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |