Trim numbers to x decimal places

  • Thread starter Thread starter Andrea
  • Start date Start date
A

Andrea

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
 
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
 
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


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

.
 
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


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
.


.
 
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

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

.
 
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

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
.
.
 
Back
Top