|If I copy'n'paste your code into an online C# compiler:
public class Program
public static void Main()
string inputString = "A1+0001852Kg 054";
string weightValueString = inputString.Substring(3, inputString.IndexOf("Kg") - 3);
double weightKg = double.Parse(weightValueString) / 1000;
string formattedWeight = weightKg.ToString("N2");
}And run it, I get what I expect:
1.85Which 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.