Main Site Documentation

String format throws error in 0.7


#1

There is some kind of formatting bug here…

double percent = 0.5;

Works:
Debug.WriteLine($“Compressor/Fan speed: {percent}”);

Doesn’t work:
Debug.WriteLine($“Compressor/Fan speed: {percent:0.00}”);

The thread ‘’ (0x2) has exited with code 0 (0x0).
#### Exception System.ArgumentException - 0x00000000 (1) ####
#### Message:
#### System.Number::ValidateFormat [IP: 0062] ####
#### System.Number::Format [IP: 0008] ####
#### System.Double::ToString [IP: 000e] ####
#### System.String::Format [IP: 025f] ####
#### System.String::Format [IP: 0006] ####
#### Ecu.Program::Run [IP: 0042] ####
#### Ecu.Program::Main [IP: 0009] ####
Exception thrown: ‘System.ArgumentException’ in mscorlib.dll
An unhandled exception of type ‘System.ArgumentException’ occurred in mscorlib.dll

At:
mscorlib.dll!System.Number.ValidateFormat(string format, out char formatCh, out int precision) + 0x70 bytes Non-user code. Skipped loading symbols.
mscorlib.dll!System.Number.Format(object value, bool isInteger, string format, System.Globalization.NumberFormatInfo info) + 0x7 bytes Non-user code. Skipped loading symbols.
mscorlib.dll!double.ToString(string format, System.IFormatProvider provider) + 0x11 bytes Non-user code. Skipped loading symbols.
mscorlib.dll!string.Format(System.IFormatProvider provider, string format, object[] args) + 0x2b6 bytes Non-user code. Skipped loading symbols.
mscorlib.dll!string.Format(string format, object[] args) + 0x5 bytes Non-user code. Skipped loading symbols.

Ecu.exe!Ecu.Program.Run() Line 177 + 0x55 bytes C# Symbols loaded.
Ecu.exe!Ecu.Program.Main() Line 210 + 0xa bytes C# Symbols loaded.


#2

Argument Exception means an incorrect parameter was supplied (or combination thereof). I don’t have a compiler in front of me at the moment but:

Debug.WriteLine($“Compressor/Fan speed: {percent:0.##}”);

Try that :expressionless:


#3

Currently not all formatting strings are supported. Instead, try Debug.WriteLine($"Compressor/Fan speed: {percent:N2}");


#4

That did it, thanks!