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

Scaling an object to change its key

Do details of my undergraduate title matter?

What is the precise meaning of "подсел на мак"?

Basic power tool set for Home repair and simple projects

A medieval book with a redhead girl as a main character who allies with vampires and werewolves against scientific opposition

I just entered the USA without passport control at Atlanta airport

Got a new frameset, don't know why I need this split ring collar?

How do I become a better writer when I hate reading?

I have found ports on my Samsung smart tv running a display service. What can I do with it?

How do I correctly reduce geometry on part of a mesh?

Using roof rails to set up hammock

How did the European Union reach the figure of 3% as a maximum allowed deficit?

How to avoid offending original culture when making conculture inspired from original

Can a character with the Polearm Master feat make an opportunity attack against an invisible creature that enters their reach?

How to add a сolumn from one table to another?

Kelvin type connection

How do credit card companies know what type of business I'm paying for?

How to make a villain when your PCs are villains?

How "fast" do astronomical events occur?

...and then she held the gun

How can I ping multiple IP addresses at the same time?

What does this Swiss black on yellow rectangular traffic sign with a symbol looking like a dart mean?

How to prevent cables getting intertwined

I'm yearning in grey



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













5












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
















    5












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














      5












      5








      5


      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 Jun 9 at 20:30









      Carl WollCarl Woll

      84.1k3107218




      84.1k3107218




















          1 Answer
          1






          active

          oldest

          votes


















          5












          $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









            5












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

















              5












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















                5












                5








                5





                $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 Jun 9 at 21:01









                Carl WollCarl Woll

                84.1k3107218




                84.1k3107218



























                    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

                    Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form