Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10365 > unrolled thread
| Started by | fcaleyo <fcaleyo@gmail.com> |
|---|---|
| First post | 2012-06-06 08:51 +0000 |
| Last post | 2012-06-07 09:16 +0000 |
| Articles | 6 — 6 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Converting from string to real fcaleyo <fcaleyo@gmail.com> - 2012-06-06 08:51 +0000
Re: Converting from string to real Szabolcs Horvát <szhorvat@gmail.com> - 2012-06-07 09:24 +0000
Re: Converting from string to real A Retey <awnl@gmx-topmail.de> - 2012-06-07 09:24 +0000
Re: Converting from string to real "Kevin J. McCann" <kjm@KevinMcCann.com> - 2012-06-07 09:26 +0000
Re: Converting from string to real Peter Breitfeld <phbrf@t-online.de> - 2012-06-07 09:27 +0000
Re: Converting from string to real "Nasser M. Abbasi" <nma@12000.org> - 2012-06-07 09:16 +0000
| From | fcaleyo <fcaleyo@gmail.com> |
|---|---|
| Date | 2012-06-06 08:51 +0000 |
| Subject | Converting from string to real |
| Message-ID | <jqn5mn$her$1@smc.vnet.net> |
Hi guys, I've got a problem with ToExpression[]. It seems to round large real numbers off, e.g. ToExpression["109266.75"] returns 109267., still a real, yet not exactly what the original string meant. Any idea to solve this? Many thanks fcaleyo
[toc] | [next] | [standalone]
| From | Szabolcs Horvát <szhorvat@gmail.com> |
|---|---|
| Date | 2012-06-07 09:24 +0000 |
| Message-ID | <jqps02$2gp$1@smc.vnet.net> |
| In reply to | #10365 |
On 2012.06.06. 10:51, fcaleyo wrote: > Hi guys, I've got a problem with ToExpression[]. > It seems to round large real numbers off, e.g. > ToExpression["109266.75"] returns 109267., still a real, yet not exactly what the original string meant. > Any idea to solve this? By default machine precision number are displayed only with six digits, but the precision is still there. If you position the cursor on the output cell and press space, you'll see this. Also try FractionalPart@ToExpression["109266.75"] So don't worry, only the display is truncated for convenience (in your case inconvenience but most of the time it's better not to see all 15 or so digits all at once) -- Szabolcs Horvát Visit Mathematica.SE: http://mathematica.stackexchange.com/
[toc] | [prev] | [next] | [standalone]
| From | A Retey <awnl@gmx-topmail.de> |
|---|---|
| Date | 2012-06-07 09:24 +0000 |
| Message-ID | <jqps10$2gr$1@smc.vnet.net> |
| In reply to | #10365 |
Am 06.06.2012 10:51, schrieb fcaleyo: > Hi guys, I've got a problem with ToExpression[]. > It seems to round large real numbers off, e.g. > ToExpression["109266.75"] returns 109267., still a real, yet not exactly what the original string meant. it doesn't round, it just doesn't print more than 6 digits with the default settings. > Any idea to solve this? You can use InputForm to see that it really knows all digits (and will use them for any further calculation): ToExpression["109266.75"]//InputForm You could also change the "Displayed precision" from Edit -> Preferences in the Apearance -> Numbers -> Formatting tab. Other than that, there isn't anything to solve really :-) hth, albert
[toc] | [prev] | [next] | [standalone]
| From | "Kevin J. McCann" <kjm@KevinMcCann.com> |
|---|---|
| Date | 2012-06-07 09:26 +0000 |
| Message-ID | <jqps4q$2j2$1@smc.vnet.net> |
| In reply to | #10365 |
This is an output formatting issue, and I will admit that it is annoying. Note: ToExpression["109266.75"]-109266.75 gives zero. So, the answer is correct, it is just that Mathematica formats the output by rounding it. I am not sure how to make it show the way you want in an easy fashion; however, this works NumberForm[ToExpression["109266.75"],10] but this is a formatted output "for your eyes only", i.e. DON'T do something like b = NumberForm[ToExpression["109266.75"],10] and then try to use b as a number. Kevin On 6/6/2012 4:51 AM, fcaleyo wrote: > Hi guys, I've got a problem with ToExpression[]. > It seems to round large real numbers off, e.g. > ToExpression["109266.75"] returns 109267., still a real, yet not exactly what the original string meant. > Any idea to solve this? > Many thanks > fcaleyo > > > >
[toc] | [prev] | [next] | [standalone]
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Date | 2012-06-07 09:27 +0000 |
| Message-ID | <jqps5p$2jh$1@smc.vnet.net> |
| In reply to | #10365 |
fcaleyo wrote: > Hi guys, I've got a problem with ToExpression[]. > It seems to round large real numbers off, e.g. > ToExpression["109266.75"] returns 109267., still a real, yet not exactly what the original string meant. > Any idea to solve this? > Many thanks > fcaleyo > This is only due to the fact, that Mathematica displays 6 Digits of precision. If you use ToExpression["109266.75"]//InputForm you will see, that all digits are present. -- _________________________________________________________________ Peter Breitfeld | Bad Saulgau, Germany | http://www.pBreitfeld.de
[toc] | [prev] | [next] | [standalone]
| From | "Nasser M. Abbasi" <nma@12000.org> |
|---|---|
| Date | 2012-06-07 09:16 +0000 |
| Message-ID | <jqprgo$2a3$1@smc.vnet.net> |
| In reply to | #10365 |
On 6/6/2012 3:51 AM, fcaleyo wrote:
> Hi guys, I've got a problem with ToExpression[].
> It seems to round large real numbers off, e.g.
> ToExpression["109266.75"] returns 109267., still a real, yet not
>exactly what the original string meant.
> Any idea to solve this?
> Many thanks
> fcaleyo
>
>
>
You can change the PrintPrecision to larger value
--------------------------------------------------
SetOptions[$FrontEndSession,PrintPrecision->15]
ToExpression["109266.75"]
109266.75
------------------------------------------------
To make it permanent, search your advanced
preferences (Options Inspector) for PrintPrecision
and change it there from the default 6 to any other value.
--Nasser
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web