I need to format my double value for example "12.4" into "12.40" , and "1" to "1.00" and I was searching for a function in the internet for a whole hour and can not find, or there is any other way to fix it? Everything must be seen in .xls file.
Asked
Active
Viewed 4,834 times
-4
-
2And you haven't see the ToString and the [standard numeric format strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings)? – Steve May 30 '18 at 17:57
-
@Steve, I have used math.Round(Double.Parse(taxDataRowItem),2), but it prints without zero at the end – Sangi May 30 '18 at 17:58
-
When you say "Everything must be seen in .xls file," do you mean that all the decimal places should still be visible in some Excel file or that you need two decimal places displayed in Excel? For the latter, you need to set the cell formatting in Excel to "0.00". – Andrew Morton May 30 '18 at 18:51
1 Answers
0
VB.NET has several functions to format a decimal as a string.
Dim integerNumber As Integer
integerNumber = 17843
Console.WriteLine(integerNumber.ToString("F", CultureInfo.InvariantCulture))
' Displays 17843.00
https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

Matt
- 1,354
- 10
- 18