Ramon Torras

TECHNOLOGY ENTHUSIAST

Passar de String to Double / Double to String

Parece mentira pero no es tan evidente como un Ctype o un convert.
 
 

Dim a As Double
Dim nfi As NumberFormatInfo = New NumberFormatInfonfi.NumberDecimalSeparator = . a = Double.Parse(Importe, nfi)

Para passar de Doube a String con un simple ToString basta:

a.ToString( F )   ‘ formateo con 2 decimales

———————————–

Otros casos:

number.ToString( F ) // displays number to two decimal places
number.ToString( N ) // same as F but separates thousands
number.ToString( C ) // same as N but precedes with local currency sign

If you follow the letter with a digit, then the number is formatted to that number of places. For example:

number.ToString( F4 ) // displays number to four decimal places

 

Comments are currently closed.