Click here to Skip to main content
16,019,435 members
Home / Discussions / C#
   

C#

 
AnswerRe: Entity Framework Code First - two Foreign Keys from same table Pin
Gerry Schmitz21-Mar-23 9:30
mveGerry Schmitz21-Mar-23 9:30 
AnswerRe: Entity Framework Code First - two Foreign Keys from same table Pin
jschell23-Mar-23 6:04
jschell23-Mar-23 6:04 
AnswerRe: Entity Framework Code First - two Foreign Keys from same table Pin
Richard Deeming27-Mar-23 0:35
mveRichard Deeming27-Mar-23 0:35 
QuestionHow to highlight all rows in listbox between two index values? Pin
Member 1405587917-Mar-23 1:25
Member 1405587917-Mar-23 1:25 
AnswerRe: How to highlight all rows in listbox between two index values? Pin
Pete O'Hanlon17-Mar-23 1:33
mvePete O'Hanlon17-Mar-23 1:33 
AnswerRe: How to highlight all rows in listbox between two index values? Pin
RedDk17-Mar-23 6:26
RedDk17-Mar-23 6:26 
QuestionMessage Closed Pin
15-Mar-23 20:32
Sivanujan Sivaraja15-Mar-23 20:32 
AnswerRe: Serial port listening application Pin
OriginalGriff15-Mar-23 21:02
mveOriginalGriff15-Mar-23 21:02 
If I copy'n'paste your code into an online C# compiler:
C#
using System;
					
public class Program
{
	public static void Main()
	{
		string inputString = "A1+0001852Kg 054";
		string weightValueString = inputString.Substring(3, inputString.IndexOf("Kg") - 3);
		Console.WriteLine(weightValueString);
		double weightKg = double.Parse(weightValueString) / 1000;
		string formattedWeight = weightKg.ToString("N2");
		Console.WriteLine(formattedWeight);
	}
}
And run it, I get what I expect:
Output
0001852
1.85
Which means that the problem isn't the code: it's the input string that you are actually processing - and we have no access to that, to it's source hardware, or to the code that reads it from the machine.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!


modified 16-Mar-23 3:19am.

GeneralRe: Serial port listening application Pin
Richard MacCutchan15-Mar-23 22:34
mveRichard MacCutchan15-Mar-23 22:34 
GeneralRe: Serial port listening application Pin
OriginalGriff15-Mar-23 22:41
mveOriginalGriff15-Mar-23 22:41 
GeneralRe: Serial port listening application Pin
Pete O'Hanlon16-Mar-23 0:19
mvePete O'Hanlon16-Mar-23 0:19 
GeneralRe: Serial port listening application Pin
OriginalGriff16-Mar-23 1:17
mveOriginalGriff16-Mar-23 1:17 
GeneralRe: Serial port listening application Pin
Pete O'Hanlon16-Mar-23 6:11
mvePete O'Hanlon16-Mar-23 6:11 
GeneralRe: Serial port listening application Pin
Dave Kreskowiak16-Mar-23 6:21
mveDave Kreskowiak16-Mar-23 6:21 
QuestionDownloading & Executing an Installer - User Cancels Pin
Kevin Marois13-Mar-23 12:52
professionalKevin Marois13-Mar-23 12:52 
AnswerRe: Downloading & Executing an Installer - User Cancels Pin
Dave Kreskowiak13-Mar-23 17:43
mveDave Kreskowiak13-Mar-23 17:43 
AnswerRe: Downloading & Executing an Installer - User Cancels Pin
Graeme_Grant14-Mar-23 5:39
mvaGraeme_Grant14-Mar-23 5:39 
AnswerRe: Downloading & Executing an Installer - User Cancels Pin
Alan N14-Mar-23 10:00
Alan N14-Mar-23 10:00 
GeneralRe: Downloading & Executing an Installer - User Cancels Pin
Kevin Marois14-Mar-23 11:15
professionalKevin Marois14-Mar-23 11:15 
QuestionLooking to hire a programmer Pin
Thomas Matson10-Mar-23 6:33
Thomas Matson10-Mar-23 6:33 
AnswerRe: Looking to hire a programmer Pin
OriginalGriff10-Mar-23 6:34
mveOriginalGriff10-Mar-23 6:34 
GeneralRe: Looking to hire a programmer Pin
Thomas Matson10-Mar-23 6:46
Thomas Matson10-Mar-23 6:46 
GeneralRe: Looking to hire a programmer Pin
Graeme_Grant14-Mar-23 5:20
mvaGraeme_Grant14-Mar-23 5:20 
GeneralOff topic: New icon in Reply - View Thread line in messages Pin
jsc4213-Mar-23 23:16
professionaljsc4213-Mar-23 23:16 
GeneralRe: Off topic: New icon in Reply - View Thread line in messages Pin
OriginalGriff14-Mar-23 0:15
mveOriginalGriff14-Mar-23 0:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.