PC Review


Reply
Thread Tools Rate Thread

how 2 approximate 0.1 to be 1

 
 
Hazem
Guest
Posts: n/a
 
      8th Dec 2006
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


 
Reply With Quote
 
 
 
 
Charlie Brown
Guest
Posts: n/a
 
      8th Dec 2006
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


 
Reply With Quote
 
Hazem
Guest
Posts: n/a
 
      8th Dec 2006
Many many thanks, it worked

You are wounderful

Thanks & Best Regards
"Charlie Brown" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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

>



 
Reply With Quote
 
_AnonCoward
Guest
Posts: n/a
 
      9th Dec 2006
"Hazem" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
: 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Averageif Approximate Match Pablo Microsoft Excel Discussion 2 22nd Mar 2011 09:22 PM
Days360() is only approximate Paul Microsoft Excel Misc 3 11th Aug 2009 03:00 AM
how to look up an approximate value in two columns =?Utf-8?B?RGVpc2UgQlI=?= Microsoft Excel Worksheet Functions 3 18th Aug 2007 11:29 PM
Sorting approximate dates e.g., 5-72 robboll Microsoft Access Queries 4 7th Jun 2007 06:12 PM
Approximate matches with vlookup? Keith R Microsoft Excel Worksheet Functions 2 30th Mar 2007 06:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:55 PM.