Hi,
i have a division of 2 integer that give me a result as
2,3944534 ...
how i can give e result as
2,3 ???
please help me!
Hi,
i have a division of 2 integer that give me a result as
2,3944534 ...
how i can give e result as
2,3 ???
please help me!
— the symptom you described means you have a floating result and want it shown with a single digit after the decimal. 's suggestion to use integer division removes the fractional part entirely, so it is not what you want; was right to point at rounding/formatting as the general approach. Two reliable options follow: keep the value numeric (for further math) and round or truncate it, or produce a formatted string for display.
Keep the value numeric (rounded):
Dim a As Integer = 12
Dim b As Integer = 5
Dim result As Decimal = CDec(a) / CDec(b)
Dim roundedOne As Decimal = Decimal.Round(result, 1, MidpointRounding.AwayFromZero) Truncate (cut, do not round):
Dim truncatedOne As Decimal = Decimal.Truncate(result * CDec(10)) / CDec(10) Format for display (string, respects current culture so you may see comma or dot):
Dim display As String = FormatNumber(result, 1) Use the numeric approach when you need to continue calculations; use formatting when the value is only for showing on screen or output. For financial or high-precision work prefer Decimal to Double. For more detail on the VB-format helper and the rounding API see the Microsoft documentation for the FormatNumber function () and Decimal.Round (Decimal.Round).
Jump to Post— kvprajapati 1,826Can you maybe provide some more information about what it is you are trying to do?
>division of 2 integer
Use \ integer division operator.
Can you maybe provide some more information about what it is you are trying to do?
>division of 2 integer
Use \ integer division operator.
and so,
i have a division, beetween 2 integer,
i need that the result number has only max 1 number after comma,
how?
and so,
i have a division, beetween 2 integer,
i need that the result number has only max 1 number after comma,
how?
Look into Math.Round if you want to keep the value as numeric or number.ToString(format) if the result can be a string.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.