Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jac Jac is offline
external usenet poster
 
Posts: 58
Default How to check the decimal point of floating number using macro???

Hi,

I would like to create a macro that can help me to compare the 1st decimal
point of floating numbers in a data list; then round up the number based on
the condition below:-

- if the 1st decimal point of the number(s) is .3, for example 2.3 / 8.3 /
7.3; then the numbers will be rounded to 3 / 9 / 8 respectively.
-if the 1st decimal point of the number(s) is other than .3, for example 4.1
/ 5.8 / 9.3; then the numbers will be rounded to 4 / 5 / 9 respectively.

I can get the macro done with If...Then... Else control structure but I
can't get the macro to specifically check the number(s) using the 1st decimal
point.

So, anyone has any ideal how to solve this problem???
Advise is needed over here.....

Thanking in advanced.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default How to check the decimal point of floating number using macro???

Try:

Sub jacaround()
Dim n As Integer
v = Selection.Value
t = Selection.Text
If InStr(t, ".") = 0 Then
Exit Sub
End If
s = Split(t, ".")
If s(1) = "" Then
Exit Sub
End If
n = Left(s(1), 1)
If n = 3 Then
Selection.Value = Fix(v) + 1
Else
Selection.Value = Fix(v)
End If
End Sub

--
Gary''s Student - gsnu200722


"Jac" wrote:

Hi,

I would like to create a macro that can help me to compare the 1st decimal
point of floating numbers in a data list; then round up the number based on
the condition below:-

- if the 1st decimal point of the number(s) is .3, for example 2.3 / 8.3 /
7.3; then the numbers will be rounded to 3 / 9 / 8 respectively.
-if the 1st decimal point of the number(s) is other than .3, for example 4.1
/ 5.8 / 9.3; then the numbers will be rounded to 4 / 5 / 9 respectively.

I can get the macro done with If...Then... Else control structure but I
can't get the macro to specifically check the number(s) using the 1st decimal
point.

So, anyone has any ideal how to solve this problem???
Advise is needed over here.....

Thanking in advanced.


  #3   Report Post  
Posted to microsoft.public.excel.programming
Jac Jac is offline
external usenet poster
 
Posts: 58
Default How to check the decimal point of floating number using macro?

Thanks for your help....
will try out the code!

: )


"Gary''s Student" wrote:

Try:

Sub jacaround()
Dim n As Integer
v = Selection.Value
t = Selection.Text
If InStr(t, ".") = 0 Then
Exit Sub
End If
s = Split(t, ".")
If s(1) = "" Then
Exit Sub
End If
n = Left(s(1), 1)
If n = 3 Then
Selection.Value = Fix(v) + 1
Else
Selection.Value = Fix(v)
End If
End Sub

--
Gary''s Student - gsnu200722


"Jac" wrote:

Hi,

I would like to create a macro that can help me to compare the 1st decimal
point of floating numbers in a data list; then round up the number based on
the condition below:-

- if the 1st decimal point of the number(s) is .3, for example 2.3 / 8.3 /
7.3; then the numbers will be rounded to 3 / 9 / 8 respectively.
-if the 1st decimal point of the number(s) is other than .3, for example 4.1
/ 5.8 / 9.3; then the numbers will be rounded to 4 / 5 / 9 respectively.

I can get the macro done with If...Then... Else control structure but I
can't get the macro to specifically check the number(s) using the 1st decimal
point.

So, anyone has any ideal how to solve this problem???
Advise is needed over here.....

Thanking in advanced.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default How to check the decimal point of floating number using macro?

Update this post if problems arise
--
Gary''s Student - gsnu200722


"Jac" wrote:

Thanks for your help....
will try out the code!

: )


"Gary''s Student" wrote:

Try:

Sub jacaround()
Dim n As Integer
v = Selection.Value
t = Selection.Text
If InStr(t, ".") = 0 Then
Exit Sub
End If
s = Split(t, ".")
If s(1) = "" Then
Exit Sub
End If
n = Left(s(1), 1)
If n = 3 Then
Selection.Value = Fix(v) + 1
Else
Selection.Value = Fix(v)
End If
End Sub

--
Gary''s Student - gsnu200722


"Jac" wrote:

Hi,

I would like to create a macro that can help me to compare the 1st decimal
point of floating numbers in a data list; then round up the number based on
the condition below:-

- if the 1st decimal point of the number(s) is .3, for example 2.3 / 8.3 /
7.3; then the numbers will be rounded to 3 / 9 / 8 respectively.
-if the 1st decimal point of the number(s) is other than .3, for example 4.1
/ 5.8 / 9.3; then the numbers will be rounded to 4 / 5 / 9 respectively.

I can get the macro done with If...Then... Else control structure but I
can't get the macro to specifically check the number(s) using the 1st decimal
point.

So, anyone has any ideal how to solve this problem???
Advise is needed over here.....

Thanking in advanced.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default How to check the decimal point of floating number using macro???

On Wed, 16 May 2007 06:06:02 -0700, Jac wrote:

Hi,

I would like to create a macro that can help me to compare the 1st decimal
point of floating numbers in a data list; then round up the number based on
the condition below:-

- if the 1st decimal point of the number(s) is .3, for example 2.3 / 8.3 /
7.3; then the numbers will be rounded to 3 / 9 / 8 respectively.
-if the 1st decimal point of the number(s) is other than .3, for example 4.1
/ 5.8 / 9.3; then the numbers will be rounded to 4 / 5 / 9 respectively.

I can get the macro done with If...Then... Else control structure but I
can't get the macro to specifically check the number(s) using the 1st decimal
point.

So, anyone has any ideal how to solve this problem???
Advise is needed over here.....

Thanking in advanced.



Function RndPt3UP(rg As Range) As Double
Dim lTemp As Long
Dim lDec As Long

lTemp = Int(rg.Value * 10)

Select Case Abs(lTemp Mod 10)
Case 3
RndPt3UP = Application.WorksheetFunction.RoundUp(rg, 0)
Case Else
RndPt3UP = Application.WorksheetFunction.RoundDown(rg, 0)
End Select

End Function

The routine will handle both positive and negative numbers. Depending on how
you want to handle negative numbers, you may want to do some modifications.

--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
decimal point in general number [email protected] New Users to Excel 2 September 18th 11 11:04 PM
starts with decimal point only if number is like 0.###... markx Excel Worksheet Functions 3 September 14th 07 12:10 PM
Check if there is a decimal point Janos Excel Programming 4 April 11th 07 04:48 PM
Floating point number comparison Edward Ulle Excel Programming 4 March 27th 06 04:13 PM
Converting 2-place decimal value to floating point decimal number with leading zero Kermit Piper Excel Discussion (Misc queries) 3 March 18th 06 06:20 PM


All times are GMT +1. The time now is 06:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"