Augment Export function to support custom number formattingDoes Mathematica support variable frame rate for any video format, in analogue of GIF-style “DisplayDurations”?Converting a notebook to plain text programmaticallyAutomatizing PSfrag exportTeXForm and large brackets (Biggl[ etc)Export Tube with VertexColors to 3DSIs there any way to export vector graphics with shading?Classifying images in mass with URLs and CSV fileExport plots to Word 2016 using EMF: Many solutions, but one open issueExport list of numbers as one column in a specified number formatcontrol symmetry property when exporting matrix as Matrix Market format .mtx

Was planting UN flag on Moon ever discussed?

Do you have to have figures when playing D&D?

How and why do references in academic papers work?

Diatonic chords of a pentatonic vs blues scale?

Why is the length of the Kelvin unit of temperature equal to that of the Celsius unit?

Breaking changes to eieio in Emacs 27?

YA book about blind creatures that live underground and take kid's eyes

Was Self-modifying-code possible just using BASIC?

Oil draining out shortly after turbo hose detached/broke

C++ logging library

What would be the way to say "just saying" in German? (Not the literal translation)

Extracting data from Plot

How to befriend someone who doesn't like to talk?

What STL algorithm can determine if exactly one item in a container satisfies a predicate?

I've been given a project I can't complete, what should I do?

Housemarks (superimposed & combined letters, heraldry)

What should I be wary of when insurer is taking a lot of time to decide whether car is repairable or a total loss?

Suppose leased car is totalled: what are financial implications?

Grep Match and extract

As easy as Three, Two, One... How fast can you go from Five to Four?

So a part of my house disappeared... But not because of a chunk resetting

Command of files and size

Why did Intel abandon unified CPU cache?

Do you really need a KDF when you have a PRF?



Augment Export function to support custom number formatting


Does Mathematica support variable frame rate for any video format, in analogue of GIF-style “DisplayDurations”?Converting a notebook to plain text programmaticallyAutomatizing PSfrag exportTeXForm and large brackets (Biggl[ etc)Export Tube with VertexColors to 3DSIs there any way to export vector graphics with shading?Classifying images in mass with URLs and CSV fileExport plots to Word 2016 using EMF: Many solutions, but one open issueExport list of numbers as one column in a specified number formatcontrol symmetry property when exporting matrix as Matrix Market format .mtx













3












$begingroup$


It's a shame that the Export framework provides no support for custom formatting of real numbers. Is it possible to augment the framework so that a "NumberForm" option can be passed in that specifies what NumberForm arguments should be used to format real numbers?



As an example:



ExportString[3.14159, "Text", "NumberForm"->3, NumberPoint->","]


should produce:




"3,14"











share|improve this question









$endgroup$
















    3












    $begingroup$


    It's a shame that the Export framework provides no support for custom formatting of real numbers. Is it possible to augment the framework so that a "NumberForm" option can be passed in that specifies what NumberForm arguments should be used to format real numbers?



    As an example:



    ExportString[3.14159, "Text", "NumberForm"->3, NumberPoint->","]


    should produce:




    "3,14"











    share|improve this question









    $endgroup$














      3












      3








      3


      1



      $begingroup$


      It's a shame that the Export framework provides no support for custom formatting of real numbers. Is it possible to augment the framework so that a "NumberForm" option can be passed in that specifies what NumberForm arguments should be used to format real numbers?



      As an example:



      ExportString[3.14159, "Text", "NumberForm"->3, NumberPoint->","]


      should produce:




      "3,14"











      share|improve this question









      $endgroup$




      It's a shame that the Export framework provides no support for custom formatting of real numbers. Is it possible to augment the framework so that a "NumberForm" option can be passed in that specifies what NumberForm arguments should be used to format real numbers?



      As an example:



      ExportString[3.14159, "Text", "NumberForm"->3, NumberPoint->","]


      should produce:




      "3,14"








      export output-formatting customization number-form






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 8 hours ago









      Carl WollCarl Woll

      83.3k3105216




      83.3k3105216




















          1 Answer
          1






          active

          oldest

          votes


















          3












          $begingroup$

          Both Export and ExportString use the common function System`ConvertersDump`ExportInternal to produce their output. In particular, any options that are fed to Export and ExportString will be present as an option to System`ConvertersDump`ExportInternal. So, we can overload this function to enable customized processing of real numbers. There are at least two mechanisms by which the built-in code processes real numbers: The formats "Table", "CSV" and others use CForm to format real numbers, while the format "Text" uses ToString with InputForm to format real numbers. So, the following function modifies both CForm and Real so that custom formatting occurs:



          System`ConvertersDump`ExportInternal[channel_, expr_, format_List, opts___] := With[
          nf = Lookup[Flatten@opts, "NumberForm"],

          With[args=Sequence@@nf,
          Internal`InheritedBlock[CForm, Real,
          Unprotect[Real,CForm];
          CForm=OutputForm@linearNumberForm[#,args]&;
          Format[r_Real,InputForm]:=OutputForm@linearNumberForm[r,args];
          System`ConvertersDump`ExportInternal[channel,expr,format,"NumberForm"->,opts]
          ]
          ] /; !MatchQ[nf, ]
          ]

          linearNumberForm[e_, args__]:=With[boxes = ToBoxes[NumberForm[e, args]],
          Replace[boxes,
          TagBox[InterpretationBox[r_, ___],___]:>stringify[r]
          ]
          ]

          stringify[s_String]:=If[StringMatchQ[s,""*""],StringTake[s,2,-2],s]
          stringify[RowBox[s_]]:=StringJoin[Replace[s, x_:>stringify[x],1]]
          stringify[SuperscriptBox[_, e_]]:="10^"<>stringify[e]


          Examples:



          ExportString[N@Pi, "Text", "NumberForm"->4, NumberPoint->","]
          ExportString[(N@Pi)^100, "Text", "NumberForm"->5,5, NumberMultiplier->"*", ExponentFunction->(#&)]



          "3,142"



          "5.18780*10^49"




          I haven't checked this code for a variety of NumberForm options, so please try it out and let me know of any deficiencies.






          share|improve this answer









          $endgroup$













            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "387"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f200027%2faugment-export-function-to-support-custom-number-formatting%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3












            $begingroup$

            Both Export and ExportString use the common function System`ConvertersDump`ExportInternal to produce their output. In particular, any options that are fed to Export and ExportString will be present as an option to System`ConvertersDump`ExportInternal. So, we can overload this function to enable customized processing of real numbers. There are at least two mechanisms by which the built-in code processes real numbers: The formats "Table", "CSV" and others use CForm to format real numbers, while the format "Text" uses ToString with InputForm to format real numbers. So, the following function modifies both CForm and Real so that custom formatting occurs:



            System`ConvertersDump`ExportInternal[channel_, expr_, format_List, opts___] := With[
            nf = Lookup[Flatten@opts, "NumberForm"],

            With[args=Sequence@@nf,
            Internal`InheritedBlock[CForm, Real,
            Unprotect[Real,CForm];
            CForm=OutputForm@linearNumberForm[#,args]&;
            Format[r_Real,InputForm]:=OutputForm@linearNumberForm[r,args];
            System`ConvertersDump`ExportInternal[channel,expr,format,"NumberForm"->,opts]
            ]
            ] /; !MatchQ[nf, ]
            ]

            linearNumberForm[e_, args__]:=With[boxes = ToBoxes[NumberForm[e, args]],
            Replace[boxes,
            TagBox[InterpretationBox[r_, ___],___]:>stringify[r]
            ]
            ]

            stringify[s_String]:=If[StringMatchQ[s,""*""],StringTake[s,2,-2],s]
            stringify[RowBox[s_]]:=StringJoin[Replace[s, x_:>stringify[x],1]]
            stringify[SuperscriptBox[_, e_]]:="10^"<>stringify[e]


            Examples:



            ExportString[N@Pi, "Text", "NumberForm"->4, NumberPoint->","]
            ExportString[(N@Pi)^100, "Text", "NumberForm"->5,5, NumberMultiplier->"*", ExponentFunction->(#&)]



            "3,142"



            "5.18780*10^49"




            I haven't checked this code for a variety of NumberForm options, so please try it out and let me know of any deficiencies.






            share|improve this answer









            $endgroup$

















              3












              $begingroup$

              Both Export and ExportString use the common function System`ConvertersDump`ExportInternal to produce their output. In particular, any options that are fed to Export and ExportString will be present as an option to System`ConvertersDump`ExportInternal. So, we can overload this function to enable customized processing of real numbers. There are at least two mechanisms by which the built-in code processes real numbers: The formats "Table", "CSV" and others use CForm to format real numbers, while the format "Text" uses ToString with InputForm to format real numbers. So, the following function modifies both CForm and Real so that custom formatting occurs:



              System`ConvertersDump`ExportInternal[channel_, expr_, format_List, opts___] := With[
              nf = Lookup[Flatten@opts, "NumberForm"],

              With[args=Sequence@@nf,
              Internal`InheritedBlock[CForm, Real,
              Unprotect[Real,CForm];
              CForm=OutputForm@linearNumberForm[#,args]&;
              Format[r_Real,InputForm]:=OutputForm@linearNumberForm[r,args];
              System`ConvertersDump`ExportInternal[channel,expr,format,"NumberForm"->,opts]
              ]
              ] /; !MatchQ[nf, ]
              ]

              linearNumberForm[e_, args__]:=With[boxes = ToBoxes[NumberForm[e, args]],
              Replace[boxes,
              TagBox[InterpretationBox[r_, ___],___]:>stringify[r]
              ]
              ]

              stringify[s_String]:=If[StringMatchQ[s,""*""],StringTake[s,2,-2],s]
              stringify[RowBox[s_]]:=StringJoin[Replace[s, x_:>stringify[x],1]]
              stringify[SuperscriptBox[_, e_]]:="10^"<>stringify[e]


              Examples:



              ExportString[N@Pi, "Text", "NumberForm"->4, NumberPoint->","]
              ExportString[(N@Pi)^100, "Text", "NumberForm"->5,5, NumberMultiplier->"*", ExponentFunction->(#&)]



              "3,142"



              "5.18780*10^49"




              I haven't checked this code for a variety of NumberForm options, so please try it out and let me know of any deficiencies.






              share|improve this answer









              $endgroup$















                3












                3








                3





                $begingroup$

                Both Export and ExportString use the common function System`ConvertersDump`ExportInternal to produce their output. In particular, any options that are fed to Export and ExportString will be present as an option to System`ConvertersDump`ExportInternal. So, we can overload this function to enable customized processing of real numbers. There are at least two mechanisms by which the built-in code processes real numbers: The formats "Table", "CSV" and others use CForm to format real numbers, while the format "Text" uses ToString with InputForm to format real numbers. So, the following function modifies both CForm and Real so that custom formatting occurs:



                System`ConvertersDump`ExportInternal[channel_, expr_, format_List, opts___] := With[
                nf = Lookup[Flatten@opts, "NumberForm"],

                With[args=Sequence@@nf,
                Internal`InheritedBlock[CForm, Real,
                Unprotect[Real,CForm];
                CForm=OutputForm@linearNumberForm[#,args]&;
                Format[r_Real,InputForm]:=OutputForm@linearNumberForm[r,args];
                System`ConvertersDump`ExportInternal[channel,expr,format,"NumberForm"->,opts]
                ]
                ] /; !MatchQ[nf, ]
                ]

                linearNumberForm[e_, args__]:=With[boxes = ToBoxes[NumberForm[e, args]],
                Replace[boxes,
                TagBox[InterpretationBox[r_, ___],___]:>stringify[r]
                ]
                ]

                stringify[s_String]:=If[StringMatchQ[s,""*""],StringTake[s,2,-2],s]
                stringify[RowBox[s_]]:=StringJoin[Replace[s, x_:>stringify[x],1]]
                stringify[SuperscriptBox[_, e_]]:="10^"<>stringify[e]


                Examples:



                ExportString[N@Pi, "Text", "NumberForm"->4, NumberPoint->","]
                ExportString[(N@Pi)^100, "Text", "NumberForm"->5,5, NumberMultiplier->"*", ExponentFunction->(#&)]



                "3,142"



                "5.18780*10^49"




                I haven't checked this code for a variety of NumberForm options, so please try it out and let me know of any deficiencies.






                share|improve this answer









                $endgroup$



                Both Export and ExportString use the common function System`ConvertersDump`ExportInternal to produce their output. In particular, any options that are fed to Export and ExportString will be present as an option to System`ConvertersDump`ExportInternal. So, we can overload this function to enable customized processing of real numbers. There are at least two mechanisms by which the built-in code processes real numbers: The formats "Table", "CSV" and others use CForm to format real numbers, while the format "Text" uses ToString with InputForm to format real numbers. So, the following function modifies both CForm and Real so that custom formatting occurs:



                System`ConvertersDump`ExportInternal[channel_, expr_, format_List, opts___] := With[
                nf = Lookup[Flatten@opts, "NumberForm"],

                With[args=Sequence@@nf,
                Internal`InheritedBlock[CForm, Real,
                Unprotect[Real,CForm];
                CForm=OutputForm@linearNumberForm[#,args]&;
                Format[r_Real,InputForm]:=OutputForm@linearNumberForm[r,args];
                System`ConvertersDump`ExportInternal[channel,expr,format,"NumberForm"->,opts]
                ]
                ] /; !MatchQ[nf, ]
                ]

                linearNumberForm[e_, args__]:=With[boxes = ToBoxes[NumberForm[e, args]],
                Replace[boxes,
                TagBox[InterpretationBox[r_, ___],___]:>stringify[r]
                ]
                ]

                stringify[s_String]:=If[StringMatchQ[s,""*""],StringTake[s,2,-2],s]
                stringify[RowBox[s_]]:=StringJoin[Replace[s, x_:>stringify[x],1]]
                stringify[SuperscriptBox[_, e_]]:="10^"<>stringify[e]


                Examples:



                ExportString[N@Pi, "Text", "NumberForm"->4, NumberPoint->","]
                ExportString[(N@Pi)^100, "Text", "NumberForm"->5,5, NumberMultiplier->"*", ExponentFunction->(#&)]



                "3,142"



                "5.18780*10^49"




                I haven't checked this code for a variety of NumberForm options, so please try it out and let me know of any deficiencies.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 7 hours ago









                Carl WollCarl Woll

                83.3k3105216




                83.3k3105216



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Mathematica Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f200027%2faugment-export-function-to-support-custom-number-formatting%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                    Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                    Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її