Group Abstract Group Abstract

Message Boards Message Boards

0
|
12.2K Views
|
5 Replies
|
1 Total Like
View groups...
Share
Share this post:

Trimming trailing zeros from a number?

Posted 10 years ago

Hi,

I am creating many lists during a calculation and finally report some of them. Couple of them have insignificant trailing zeros such as:

a=1.23000000000000000000000  

and I would like to trim those zeros. I was thinking something like

N[a,Accuracy[a]] 

but it is not working.

Is there a way of doing this?

POSTED BY: Erdem Uguz
5 Replies

If you just want to trim padded 0's use InputForm[a, NumberMarks->False] That will yield 1.23 without changing a.

POSTED BY: John Vande Vate
Posted 10 years ago

Maybe you could use rounding and $MachineEpsilon to get rid of the trailing zeros:

a = {1.000000000000000000, 2.000000000000000000}; (*this is the position*)

b = {1.456783454656574576, 4.546562323253456534}; (*value at that position*)

c = Round[#, $MachineEpsilon] & /@ Transpose[{a, b}]

{{1., 1.45678}, {2., 4.54656}}

FortranForm@c

List(List(1.,1.4567834546565746),List(2.,4.546562323253457))

$MachineEpsilon

2.22045*10^-16

POSTED BY: Hans Milton
Posted 10 years ago
POSTED BY: Erdem Uguz
POSTED BY: Jason Biggs
Posted 10 years ago

Thank you for you reply I am exporting the data as .csv , I found that is the best way of keeping all the digits. FortranForm does what I need but with one problem. Here is an example what I am doing.

   A = {1.000000000000000000, 2.000000000000000000}; (*this is the position*)
    B = {1.456783454656574576, 4.546562323253456534}; (*value at that position*)
   C=Transpose[{A, B}]   (*and I write C to .csv file*)

And when I use FortranForm on A it is not anymore a list therefore I can't create C.

POSTED BY: Erdem Uguz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard