Click here to Skip to main content
15,113,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

This is related to a question that I posed yesterday got an answer to and it worked! (thanks PK Fox & Original Griff) The problem is now that I am reading a value from a frequency counter of around 1.8432 MHz I need to convert this to hertz: 1843200 Hz and multiply by six to give 11059200 HZ I then need to send this out to the DUT.
The things are bothering me about this converting from a String to a Long, I can read in 1.8432 MHz and then use substring to get rid of the MHz (via blah.Substring(0, blah.Length-4). Can Decimal.Parse which I used yesterday for converting Amps to mA be used again bearing in mind I want to multiply by 6?
Does this question make sense?

1 solution

Yes - decimal.Parse converts it to a decimal value.
So multiply the decimal by 6 (or 6000 to convert from A to mA) and cast it as a long:
Dim mA As Long = CLng(Math.Truncate(Decimal.Parse("1.8432") * 6 * 1000))
glennPattonInThePub3 10-Apr-14 9:40am
Thanks for that, I will try it! Mind you you start to get frustrated when you see you question poping up in Google....
glennPattonInThePub3 10-Apr-14 10:01am
Given it a go it does what I was finding earlier was problems getting the String to a Decimal so I could do the multiply by 6
glennPattonInThePub3 10-Apr-14 10:12am
FreqResult1823_Trimmed = System.Convert.ToDecimal(result1823A_Trimmed) appears to round to the decimal point.
glennPattonInThePub3 10-Apr-14 10:19am
Ah! CDec my old nemesis....
glennPattonInThePub3 10-Apr-14 10:21am
Accepting and closing question as I think I have a solution!!! Have a 5 as you got thinking the right way!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900