Skip to main content
8 events
when toggle format what by license comment
Dec 31, 2018 at 22:36 comment added theorist @Ruslan I encountered a case in which your suggested addition causes george2079's code to break where it otherwise would have been fine: When there is a trailing decimal point (e.g., 100./3). One might encounter these if you've deliberately added trailing decimals to numericize evaluations within a notebook, and then use george's code to conveniently reevaluate the notebook using exact numbers.
Feb 26, 2018 at 7:57 comment added Ruslan @theorist not quite: insert it before the trailing semicolon — to make the pattern conditional
Feb 26, 2018 at 7:43 comment added theorist @Ruslan: By "append to the end of fract" do you mean exactly this?: fract[s_String] := (ToExpression[StringReplace[s, "." -> ""]]/ 10^(StringLength[s] - First@First@StringPosition[s, "."]));/; StringMatchQ[s, RegularExpression["[+-]?[0-9]*\\.[0-9]+"]]
Apr 9, 2017 at 9:06 comment added Ruslan May be a good idea to append /; StringMatchQ[s, RegularExpression["[+-]?[0-9]*\\.[0-9]+"]] to your fract: this will avoid all the possible breakage with unexpected formats of the string, returning unevaluated expression instead.
Mar 14, 2017 at 18:11 history edited george2079 CC BY-SA 3.0
deleted 23 characters in body
Apr 15, 2014 at 16:57 comment added george2079 The point is to work with the actual text entered to avoid some of the issues raised in the comments arising from conversion to/from machine precision. (As a practical matter those issues may not be important, and using $Pre like that is clearly cleaner and more robust )
Apr 15, 2014 at 16:06 comment added Simon Woods How about $Pre = # /. r_Real :> RuleCondition[Round[r, 10^-Ceiling@Precision@r]] &
Apr 15, 2014 at 15:30 history answered george2079 CC BY-SA 3.0