Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Trim numbers to x decimal places

Help please !!!!

I am trying to write some code that will trim general
numbers.

e.g. 123.123456789 to 123.1234

I have looked at Trim Statements but these only seem to
apply to characters and spacing.

Thanks Andrea
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Trim numbers to x decimal places

Hi
try
=TRUNC(123.1234567,4)

--
Regards
Frank Kabel
Frankfurt, Germany

Andrea wrote:
Help please !!!!

I am trying to write some code that will trim general
numbers.

e.g. 123.123456789 to 123.1234

I have looked at Trim Statements but these only seem to
apply to characters and spacing.

Thanks Andrea

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Trim numbers to x decimal places

Hi Andrea,

Check the ROUND or TRUNC function.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Help please !!!!

I am trying to write some code that will trim general
numbers.

e.g. 123.123456789 to 123.1234

I have looked at Trim Statements but these only seem to
apply to characters and spacing.

Thanks Andrea

  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Trim numbers to x decimal places

Hi Frank/Tushar

Thank you for both replies -

I've tried your suggestions, but I think an 'If' or 'case
statement' is required. I'm a VB beginner as you may have
worked out.

Something like:

Dim result As Variant
Dim number As Variant

number = Rst![Total]

Result = number

If number is .0000 then

Trim to .0000 '(4 decimal places)

frmMain.txtResult.Text = (Result)

However I do not know how to write this in VB and have
spent hours searching for an answer.

I hope I have made this a little clearer.

I would appreciate any help.

Thanks Andrea

-----Original Message-----
Hi
try
=TRUNC(123.1234567,4)

--
Regards
Frank Kabel
Frankfurt, Germany

Andrea wrote:
Help please !!!!

I am trying to write some code that will trim general
numbers.

e.g. 123.123456789 to 123.1234

I have looked at Trim Statements but these only seem to
apply to characters and spacing.

Thanks Andrea

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trim numbers to x decimal places

Dim result As Variant
Dim number As Variant

number = Rst![Total]

Result = number

If len(Number) len(Format(Number,"#.0000") then

Result = cdbl(format(Number,#.0000"))
End if

frmMain.txtResult.Text = (Result)

--
Regards,
Tom Ogilvy


wrote in message
...
Hi Frank/Tushar

Thank you for both replies -

I've tried your suggestions, but I think an 'If' or 'case
statement' is required. I'm a VB beginner as you may have
worked out.

Something like:

Dim result As Variant
Dim number As Variant

number = Rst![Total]

Result = number

If number is .0000 then

Trim to .0000 '(4 decimal places)

frmMain.txtResult.Text = (Result)

However I do not know how to write this in VB and have
spent hours searching for an answer.

I hope I have made this a little clearer.

I would appreciate any help.

Thanks Andrea

-----Original Message-----
Hi
try
=TRUNC(123.1234567,4)

--
Regards
Frank Kabel
Frankfurt, Germany

Andrea wrote:
Help please !!!!

I am trying to write some code that will trim general
numbers.

e.g. 123.123456789 to 123.1234

I have looked at Trim Statements but these only seem to
apply to characters and spacing.

Thanks Andrea

.





  #6   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Trim numbers to x decimal places

TOM

Great !!! this works a treat.

Thank you...Thank you... Thank you...

Andrea

-----Original Message-----
Dim result As Variant
Dim number As Variant

number = Rst![Total]

Result = number

If len(Number) len(Format(Number,"#.0000") then

Result = cdbl(format(Number,#.0000"))
End if

frmMain.txtResult.Text = (Result)

--
Regards,
Tom Ogilvy


wrote in message
...
Hi Frank/Tushar

Thank you for both replies -

I've tried your suggestions, but I think an 'If' or

'case
statement' is required. I'm a VB beginner as you may

have
worked out.

Something like:

Dim result As Variant
Dim number As Variant

number = Rst![Total]

Result = number

If number is .0000 then

Trim to .0000 '(4 decimal places)

frmMain.txtResult.Text = (Result)

However I do not know how to write this in VB and have
spent hours searching for an answer.

I hope I have made this a little clearer.

I would appreciate any help.

Thanks Andrea

-----Original Message-----
Hi
try
=TRUNC(123.1234567,4)

--
Regards
Frank Kabel
Frankfurt, Germany

Andrea wrote:
Help please !!!!

I am trying to write some code that will trim general
numbers.

e.g. 123.123456789 to 123.1234

I have looked at Trim Statements but these only seem

to
apply to characters and spacing.

Thanks Andrea
.



.

  #8   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Trim numbers to x decimal places

Hi Tushar

I have hundreds of text boxes to code. The data to
populate these ranges from 1 to 10 decimal places and I
need whole numbers to 0.

I am new to Vb so I'm sure your suggestion will come in
useful for future developments.

Thanks again Andrea

-----Original Message-----
I imagine Tom's code does the job, but I don't see the

need for a test
as you want. Doesn't the following do the job?

frmMain.txtResult.Text = Round(Rst![Total],4)

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Hi Frank/Tushar

Thank you for both replies -

I've tried your suggestions, but I think an 'If' or

'case
statement' is required. I'm a VB beginner as you may

have
worked out.

Something like:

Dim result As Variant
Dim number As Variant

number = Rst![Total]

Result = number

If number is .0000 then

Trim to .0000 '(4 decimal places)

frmMain.txtResult.Text = (Result)

However I do not know how to write this in VB and have
spent hours searching for an answer.

I hope I have made this a little clearer.

I would appreciate any help.

Thanks Andrea

-----Original Message-----
Hi
try
=TRUNC(123.1234567,4)

--
Regards
Frank Kabel
Frankfurt, Germany

Andrea wrote:
Help please !!!!

I am trying to write some code that will trim general
numbers.

e.g. 123.123456789 to 123.1234

I have looked at Trim Statements but these only seem

to
apply to characters and spacing.

Thanks Andrea
.


.

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
enter numbers without decimal places wt.pm Excel Discussion (Misc queries) 3 July 30th 09 06:33 PM
Why do my numbers keep going down decimal places? Excell2002ishard Setting up and Configuration of Excel 2 March 27th 08 09:36 PM
Why do my numbers keep going down decimal places? Excell2002ishard Setting up and Configuration of Excel 2 March 27th 08 08:09 PM
Sum of numbers with only two decimal places wrong Excelgonecrazy Excel Discussion (Misc queries) 2 November 13th 07 07:21 PM
Subtracting two 2-decimal place numbers gives result 13-decimal places? [email protected] Excel Worksheet Functions 5 March 12th 07 10:38 PM


All times are GMT +1. The time now is 10:18 PM.

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

About Us

"It's about Microsoft Excel"