How can I produce the exact decimal values - vb.net

Code:
Dim mp as Decimal
mp = 2056834 / 36
MsgBox(mp, vbInformation)
Output: 57134.2777777778
I was expecting the output to be:
Output: 57134.27777777778
What suppose to be the problem on why it was short of a decimal point?

Try this:
Dim mp As Decimal
mp = Math.Round(CDec(2056834) / CDec(36), 11)
MsgBox(mp, vbInformation)
This will produce the expected output: 57134.27777777778

Related

Kotlin how to make 123.456 format

I have scales application. I want to display i.e. 123.456g
I have uint8 that represents 123 (scales range is 0 - 150g)
I also have uint16 that represents 456 (scales range .0 - .999g)
My code:
val strValue = characteristic.getIntValue(FORMAT_UINT16,0).toFloat() + ((characteristic.getIntValue(FORMAT_UINT16,1) or characteristic.getIntValue(FORMAT_UINT16,2).shl(8)) / 1000f)
Produces 51323.457 instead of 123.456
What is wrong?
You're adding floats, not generating a string.
Convert your digits to String, then concatenate them.

Select columns based on exact row value matches

I am trying to select columns of a specified integer value (24). However, my new dataframe includes all values = and > 24. I have tried converting from integer to both float and string, and it gives the same results. Writing "24" and 24 gives same result. The dataframe is loaded from a .csv file.
data_PM1_query24 = data_PM1.query('hours == "24"' and 'averages_590_nm_minus_blank > 0.3')
data_PM1_sorted24 = data_PM1_query24.sort_values(by=['hours', 'averages_590_nm_minus_blank'])
data_PM1_sorted24
What am I missing here?
Please try out the below codes. I'm assuming that the data type of "hours" and "averages_590_nm_minus_blank" is float. If not float, convert them to float.
data_PM1_query24 = data_PM1.query('hours == 24 & averages_590_nm_minus_blank > 0.3')
or you can also use,
data_PM1_query24 = data_PM1[(data_PM1.hours == 24) & (data.averages_590_nm_minus_blank > 0.3)]
Hope this solves your query!

VB.net Converting integer to desired format

Code
myObject.TotalTime = 745
Dim test As Integer = Integer.Parse(myObject.TotalTime)
Dim test2 As String = test.ToString("00:00:00")
Desired result : 7:45:00
Current result : "00:07:45"
anyone knows a more sufficient way to convert this? like 2lines of code or even 1 line with a use of casting and such if only possible?
You can use DateTime.ParseExact() method and use h:mm:ss format string like this:
myObject.TotalTime = 745
Dim test As Integer = Integer.Parse(myObject.TotalTime)
' since it may contains 4 digits (e.g. 1000),
' use 4 digits for parsing instead of 3
Dim test1 As DateTime = DateTime.ParseExact(test.ToString("0000"), "HHmm", CultureInfo.InvariantCulture)
Dim test2 As String = test1.ToString("h:mm:ss")
Result: 7:45:00
Working example: .NET Fiddle Demo
Related issue: Convert numbers to time?

How to remove zeroes after the decimal point as an expression in SSRS

I have the following expression in one of my textbox in my SSRS Report:
=IIF(IsNothing(Lookup(Trim(Fields!venta_Cod_vendedor.Value) & "-" & ReportItems!Textbox233.Value, Fields!AgregarVentas.Value, Fields!venta_prom_sem.Value, "EfectividadDeFrecuencias_Ventas")) = True
,"0"
,IIF(Lookup(Trim(Fields!venta_Cod_vendedor.Value) & "-" & ReportItems!Textbox233.Value, Fields!Agregar.Value, Fields!total_cant_pos.Value, "EfectividadDeFrecuencias_Total") <> "0"
,FormatNumber(Lookup(Trim(Fields!venta_Cod_vendedor.Value) & "-" & ReportItems!Textbox233.Value, Fields!AgregarVentas.Value, Fields!venta_frecuencia.Value, "EfectividadDeFrecuencias_Ventas")
/ Lookup(Trim(Fields!venta_Cod_vendedor.Value) & "-" & ReportItems!Textbox233.Value, Fields!Agregar.Value, Fields!total_cant_pos.Value, "EfectividadDeFrecuencias_Total"),2)
,"0"))
That division will give me an int64 number, 15 digits (If such math operation gives that amount of decimal digits).
So the results are:
Now here is the tricky part:
My code behind that grabs the Dataset does a round and converts to decimal and then shows to a Crystal Report.
dr.venta_prom_sem = (Convert.ToDouble(dr.total_cant_pos) != 0 ? (Math.Round((Convert.ToDouble(dr.venta_frecuencia) / Convert.ToDouble(dr.total_cant_pos)), 2)).ToString() : "0");
So this will give me:
as you can see if I use a format Number the 1.3 will convert to 1,30 and that will be wrong, same as 1 (1,00). Now 1,339...etc will give me 1,34 and that is fine.
But check the 1.065, with FormatNumber that will give me 1.07 instead of 1.06.
So the thing is, how can I format my numbers to be the last non zero digit after the decimal point AND select the lower value if the (in this case) 3rd value is 5, instead of 1.07 be 1.06. I think If I use Ceiling or Floor it gives me the integer part.
Try this:
=ROUND(1.339,2,MidpointRounding.ToEven)
This gives: 1.34
And
=ROUND(1.065,2,MidpointRounding.ToEven)
Gives: 1.06
Let me know if this was helpful.

Convert hex to binary while retaining their places

I have this code that converts 7 to binary.
Dim s As String = "7"
Dim i As Integer = Convert.ToInt32(s, 16)
Dim s2 As String = Convert.ToString(i, 2)
Console.WriteLine(s2) 'result is 111
My problem is this, I want to apply the 8 bit binary so I can easily substring the result.
Instead of the result that is 111, I would like to make it 0111.
Examples:
Binary / Hex
1. F = 1111
2. 7 = 0111
3. 1 = 0001
You can pad the result with starting zero by using PadLeft.
s2.PadLeft(4, "0")