On 10/21/2017 8:44 PM, Beliavsky wrote:
> Sometimes in finance and accounting, negative numbers are printed using parentheses instead of a negative sign, because the parentheses are harder to miss: (3.1) instead of -3.1. I wish there were Fortran formats that did this. Would anyone else like this feature?
>
> In the absence of this feature, one can write a function that converts a real to a string and supply an argument to the function that tells it to use parentheses for negative numbers.
In the past, I wrote my own print function that handled numeric prints
in the way that I liked to see them. Sadly, the function disappeared in
the 1980s while I was not looking.
In C++, I have written a polymorphic library function that allows me to
customize as necessary. I do not know if you can do something like this
in modern Fortran but if so, it might fit your needs.
std::string asString ();
std::string asString (void * val);
std::string asString (int val);
std::string asString (long val);
std::string asString (unsigned int val);
std::string asString (double val);
std::string asString (unsigned long val);
std::string asString (const char *val);
std::string asString (int val, const char * conversion);
std::string asString (long val, const char * conversion);
std::string asString (unsigned int val, const char * conversion);
std::string asString (unsigned long val, const char * conversion);
std::string asString (double val, const char * conversion);
Lynn