Imports System
' -----------------------------------------------------------------------------
' Determines whether a Double contains an integer (no fractional part).
' Uses a small tolerance to safely handle floating‑point precision issues.
' -----------------------------------------------------------------------------
Module Program
Function IsInteger(value As Double) As Boolean
Dim epsilon As Double = 1E-12
' Math.Floor returns the largest integer <= value
Dim floored As Double = Math.Floor(value)
' If the difference is extremely small, treat the number as an integer
Return Math.Abs(value - floored) < epsilon
End Function
' -----------------------------------------------------------------------------
' Prints a descriptive message for the given Double.
' -----------------------------------------------------------------------------
Sub PrintCheck(value As Double)
Console.WriteLine($"Checking value: {value:F15}")
If IsInteger(value) Then
Console.WriteLine("Result: The value contains an integer." & Environment.NewLine)
Else
Console.WriteLine("Result: The value contains a floating‑point number." & Environment.NewLine)
End If
End Sub
' -----------------------------------------------------------------------------
' Entry point demonstrating several example values.
' -----------------------------------------------------------------------------
Sub Main()
' Example input values
Dim a As Double = 42.0 ' integer-like
Dim b As Double = 42.00000000001 ' floating-point due to tiny fraction
Dim c As Double = 89.0000000000001 ' integer-like
Dim d As Double = -7.0 ' negative integer-like
Dim e As Double = 3.14 ' floating-point
' Run checks
PrintCheck(a)
PrintCheck(b)
PrintCheck(c)
PrintCheck(d)
PrintCheck(e)
End Sub
End Module
'
' run:
'
' Checking value: 42.000000000000000
' Result: The value contains an integer.
'
' Checking value: 42.000000000009997
' Result: The value contains a floating‑point number.
'
' Checking value: 89.000000000000099
' Result: The value contains an integer.
'
' Checking value: -7.000000000000000
' Result: The value contains an integer.
'
' Checking value: 3.140000000000000
' Result: The value contains a floating‑point number.
'