Message Boards Message Boards

0
|
4101 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Consistently format a real as a string for parsing to SQL?

Posted 8 years ago

I've written a routine for generating command strings to insert mostly numeric records into a SQL database. It chokes if I try to format a Real above a certain value, because it switches to scientific notation. This isn't actually a fragment of the code, but it illustrates the point:

In[1120]:= x = {7.5, 7500., 75000., 750000., 7500000.};
ToString[#] & /@  x

Out[1121]= {"7.5", "7500.", "75000.", "750000.", "      6
 7.5 10"}

I could slip an AccountingForm[] call in there, but sometimes the numbers are negative, so they get wrapped in brackets. There are plenty of long-winded solutions. Any elegant ones?

  • Brad
POSTED BY: Brad Varey
In[26]:= ToString[NumberForm[#, 0, ExponentStep -> \[Infinity]]] & /@ x

Out[26]= {"7.5", "7500.", "75000.", "750000.", "7500000."}
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract