473,503 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how 2 approximate 0.1 to be 1

Hi, I want to make a calculation & need to appriximate

any fraction after the point to be added as genuine

like 4.1 = 5

what function or syntax can I use to accomplish that in VB.net ??

Thanks

Hazem
Dec 8 '06 #1
3 2076
Dim MyNumber as Single = 4.1
Dim MyWholeNumber as Integer = Math.Ceiling(MyNumber)
Hazem wrote:
Hi, I want to make a calculation & need to appriximate

any fraction after the point to be added as genuine

like 4.1 = 5

what function or syntax can I use to accomplish that in VB.net ??

Thanks

Hazem
Dec 8 '06 #2
Many many thanks, it worked

You are wounderful

Thanks & Best Regards
"Charlie Brown" <cb****@duclaw.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
Dim MyNumber as Single = 4.1
Dim MyWholeNumber as Integer = Math.Ceiling(MyNumber)
Hazem wrote:
>Hi, I want to make a calculation & need to appriximate

any fraction after the point to be added as genuine

like 4.1 = 5

what function or syntax can I use to accomplish that in VB.net ??

Thanks

Hazem

Dec 8 '06 #3
"Hazem" <ha*********@gmail.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
: Hi, I want to make a calculation & need to appriximate
:
: any fraction after the point to be added as genuine
:
: like 4.1 = 5
:
: what function or syntax can I use to accomplish that in VB.net ??
:
: Thanks
:
: Hazem
Two approaches come to mind. Both are illustrated below:

---------------------------------------------------------
Option Strict

Imports System

Public Module [module]

PUblic Sub Main

Print_Combined_Digits_1(4.0)
Print_Combined_Digits_1(4.1)
Print_Combined_Digits_1(4.2)
Print_Combined_Digits_1(4.3)
Print_Combined_Digits_1(4.4)
Print_Combined_Digits_1(4.5)
Print_Combined_Digits_1(4.6)
Print_Combined_Digits_1(4.7)
Print_Combined_Digits_1(4.8)
Print_Combined_Digits_1(4.9)
Print_Combined_Digits_1(5.0)

Console.WriteLine()

Print_Combined_Digits_2(4.0)
Print_Combined_Digits_2(4.1)
Print_Combined_Digits_2(4.2)
Print_Combined_Digits_2(4.3)
Print_Combined_Digits_2(4.4)
Print_Combined_Digits_2(4.5)
Print_Combined_Digits_2(4.6)
Print_Combined_Digits_2(4.7)
Print_Combined_Digits_2(4.8)
Print_Combined_Digits_2(4.9)
Print_Combined_Digits_2(5.0)

End Sub

Private Sub Print_Combined_Digits_1(Number As Single)

Dim Scratch As String = FormatNumber(Number, 1)

Dim Major As Integer = CInt(Int(Number))
Dim Minor As Integer = CInt(Int(Number * 10)) Mod (Major * 10)
Dim Combined As Integer = Major + Minor

Console.WriteLIne(Scratch & ": " & Major & " + " & Minor & _
" = " & Combined)

End Sub

Private Sub Print_Combined_Digits_2(Number As Single)

Dim Scratch As String = FormatNumber(Number, 1)
Dim Digits() As String = Split(Scratch, ".")

Dim Major As Integer = CInt(Digits(0))
Dim MInor As Integer = CInt(Digits(1))
Dim Combined As Integer = Major + Minor

Console.WriteLIne(Scratch & ": " & Major & " + " & Minor & _
" = " & Combined)

End Sub

End Module
---------------------------------------------------------
This generates the following output:

4.0: 4 + 0 = 4
4.1: 4 + 1 = 5
4.2: 4 + 2 = 6
4.3: 4 + 3 = 7
4.4: 4 + 4 = 8
4.5: 4 + 5 = 9
4.6: 4 + 6 = 10
4.7: 4 + 7 = 11
4.8: 4 + 8 = 12
4.9: 4 + 9 = 13
5.0: 5 + 0 = 5

4.0: 4 + 0 = 4
4.1: 4 + 1 = 5
4.2: 4 + 2 = 6
4.3: 4 + 3 = 7
4.4: 4 + 4 = 8
4.5: 4 + 5 = 9
4.6: 4 + 6 = 10
4.7: 4 + 7 = 11
4.8: 4 + 8 = 12
4.9: 4 + 9 = 13
5.0: 5 + 0 = 5

Ralf
Dec 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3851
by: Travis Stewart | last post by:
Hi, I am not very familiar with C++ so the problems I am having might be simple and I just cannot see them or I am totally unaware of why something would be incorrect. Anyway, I'm using the ANN...
1
2515
by: boblotz2001 | last post by:
For anybody that implemented fuzzy searches in SQL Server or any other database for that matter. I have implemented edit distance algorithm, specifically q-grams, in SQL Server and wanted to get...
9
1924
by: Paul Eggert | last post by:
CBFalconer <cbfalconer@yahoo.com> writes: > It would be fairly easy to graft such a construct with: > > enum subrangetype {MINVAL .. MAXVAL}; > > where MINVAL and MAXVAL are constant...
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.