Discussion:
[dart-misc] set global default double -> string precision
Rich Eakin
2015-07-12 22:20:59 UTC
Permalink
I've been working on a simulation in dart and found the double.
toStringAsFixed() method very useful in controlling how much data gets
printout to console when I'm debugging variables. I was thinking though, it
would be nice if it was possible to set a global precision for my
application or isolate, so that I did not have to write that method in
every print statement that I make. Is there any existing discussion for
something like this, or a feature request?

cheers,
Rich
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
'Lasse R.H. Nielsen' via Dart Misc
2015-07-13 09:14:29 UTC
Permalink
Not any request or discussion that I can remember.

If you have a fixed format that you tend to use, you could use a helper
function to do the formatting for you:

int fixedPrecision = 3;
String toFixed(double value) => value.toStringAsFixed(fixedPrecision);

We don't have any printf, which is what you would normally use in other
languages, because string interpolations does most of the job very well.
A case that it doesn't handle as well is number formatting, which gets
pretty verbose.

/L
Post by Rich Eakin
I've been working on a simulation in dart and found the double.
toStringAsFixed() method very useful in controlling how much data gets
printout to console when I'm debugging variables. I was thinking though, it
would be nice if it was possible to set a global precision for my
application or isolate, so that I did not have to write that method in
every print statement that I make. Is there any existing discussion for
something like this, or a feature request?
cheers,
Rich
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an
--
Lasse R.H. Nielsen - ***@google.com
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 KÞbenhavn K
- Denmark - CVR nr. 28 86 69 84
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
k***@gmail.com
2015-07-13 10:53:33 UTC
Permalink
<html><head></head><body lang="zh-TW" style="background-color: rgb(255, 255, 255); line-height: initial;"> <div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">Adopt log library and extend it with your own implementation</div> <div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><br style="display:initial"></div> <div style="font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><br></div> <table width="100%" style="background-color:white;border-spacing:0px;"> <tbody><tr><td colspan="2" style="font-size: initial; text-align: initial; background-color: rgb(255, 255, 255);"> <div style="border-style: solid none none; border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt 0in 0in; font-family: Tahoma, 'BB Alpha Sans', 'Slate Pro'; font-size: 10pt;"> <div><b>寄件者: </b>'Lasse R.H. Nielsen' via Dart Misc</div><div><b>已傳送: </b>2015年7月13日星期一 17:14</div><div><b>收件者: </b>***@dartlang.org</div><div><b>回覆至: </b>***@dartlang.org</div><div><b>主旨: </b>Re: [dart-misc] set global default double -&gt; string precision</div></div></td></tr></tbody></table><div style="border-style: solid none none; border-top-color: rgb(186, 188, 209); border-top-width: 1pt; font-size: initial; text-align: initial; background-color: rgb(255, 255, 255);"></div><br><div id="_originalContent" style=""><div dir="ltr">Not any request or discussion that I can remember.<div><br></div><div>If you have a fixed format that you tend to use, you could use a helper function to do the formatting for you:</div><div><br></div><div>int fixedPrecision = 3;</div><div>String toFixed(double value) =&gt; value.toStringAsFixed(fixedPrecision);</div><div><br></div><div>We don't have any printf, which is what you would normally use in other languages, because string interpolations does most of the job very well.</div><div>A case that it doesn't handle as well is number formatting, which gets pretty verbose.</div><div><br></div><div>/L</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 13, 2015 at 12:20 AM, Rich Eakin <span dir="ltr">&lt;<a href="mailto:***@gmail.com" target="_blank">***@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I've been working on a simulation in dart and found the double.<span>toStringAsFixed</span>() method very useful in controlling how much data gets printout to console when I'm debugging variables. I was thinking though, it would be nice if it was possible to set a global precision for my application or isolate, so that I did not have to write that method in every print statement that I make. Is there any existing discussion for something like this, or a feature request?<div><br></div><div>cheers,</div><div>Rich &nbsp;</div></div><span class="HOEnZb"><font color="#888888">

<p></p>

-- <br>
For other discussions, see <a href="https://groups.google.com/a/dartlang.org/" target="_blank">https://groups.google.com/a/dartlang.org/</a><br>
&nbsp;<br>
For HOWTO questions, visit <a href="http://stackoverflow.com/tags/dart" target="_blank">http://stackoverflow.com/tags/dart</a><br>
&nbsp;<br>
To file a bug report or feature request, go to <a href="http://www.dartbug.com/new" target="_blank">http://www.dartbug.com/new</a><br>

<p></p>

To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:misc+***@dartlang.org" target="_blank">misc+***@dartlang.org</a>.<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Lasse R.H. Nielsen -&nbsp;<a href="mailto:***@google.com" target="_blank">***@google.com</a> &nbsp;<div>'Faith without judgement merely degrades the spirit divine'<br><font size="1" color="#999999">Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K -&nbsp;Denmark - CVR nr. 28 86 69 84</font></div></div>
</div>

<p></p>

-- <br>
For other discussions, see <a href="https://groups.google.com/a/dartlang.org/">https://groups.google.com/a/dartlang.org/</a><br>
&nbsp;<br>
For HOWTO questions, visit <a href="http://stackoverflow.com/tags/dart">http://stackoverflow.com/tags/dart</a><br>
&nbsp;<br>
To file a bug report or feature request, go to <a href="http://www.dartbug.com/new">http://www.dartbug.com/new</a><br>

<p></p>

To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:misc+***@dartlang.org">misc+***@dartlang.org</a>.<br>
<br><!--end of _originalContent --></div></body></html>

<p></p>

-- <br />
For other discussions, see <a href="https://groups.google.com/a/dartlang.org/">https://groups.google.com/a/dartlang.org/</a><br />
&nbsp;<br />
For HOWTO questions, visit <a href="http://stackoverflow.com/tags/dart">http://stackoverflow.com/tags/dart</a><br />
&nbsp;<br />
To file a bug report or feature request, go to <a href="http://www.dartbug.com/new">http://www.dartbug.com/new</a><br />

<p></p>

To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:misc+***@dartlang.org">misc+***@dartlang.org</a>.<br />
Ian Mackenzie
2015-07-14 03:53:47 UTC
Permalink
If you're not using string interpolation and just calling print(someValue),
then perhaps you could use a Zone
<https://www.dartlang.org/articles/zones/#example-overriding-print> to
override the print() function within a body of code to recognize doubles
and format them to a given precision? You could even get fancy with your
overridden print() function to allow passing it lists of arguments, and it
would concatenate the string versions of each while using your default
precision for doubles, so you could call (within the zone)

print(['The value of x is ', x, ' and the value of y is ', y]);

to get a form of string interpolation (unless of course you also want to be
able to print out lists as lists!).
Post by Rich Eakin
I've been working on a simulation in dart and found the double.
toStringAsFixed() method very useful in controlling how much data gets
printout to console when I'm debugging variables. I was thinking though, it
would be nice if it was possible to set a global precision for my
application or isolate, so that I did not have to write that method in
every print statement that I make. Is there any existing discussion for
something like this, or a feature request?
cheers,
Rich
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Rich Eakin
2015-07-15 23:13:48 UTC
Permalink
The zones is an interesting idea. Ideally though, I think it would be nice
to use the built in print function or a custom function that took the same
parameter (Object), and control how the formatting is done. The problem
with using my own custom print function (or a logging library for that
matter), is that as far as I can tell the double.toString()'s have already
happened so my function only sees a big concatenated string.
Post by Ian Mackenzie
If you're not using string interpolation and just calling
print(someValue), then perhaps you could use a Zone
<https://www.dartlang.org/articles/zones/#example-overriding-print> to
override the print() function within a body of code to recognize doubles
and format them to a given precision? You could even get fancy with your
overridden print() function to allow passing it lists of arguments, and it
would concatenate the string versions of each while using your default
precision for doubles, so you could call (within the zone)
print(['The value of x is ', x, ' and the value of y is ', y]);
to get a form of string interpolation (unless of course you also want to
be able to print out lists as lists!).
Post by Rich Eakin
I've been working on a simulation in dart and found the double.
toStringAsFixed() method very useful in controlling how much data gets
printout to console when I'm debugging variables. I was thinking though, it
would be nice if it was possible to set a global precision for my
application or isolate, so that I did not have to write that method in
every print statement that I make. Is there any existing discussion for
something like this, or a feature request?
cheers,
Rich
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Ian Mackenzie
2015-07-16 03:43:33 UTC
Permalink
Well, I suppose if your custom print function gets passed a string, you
could use a regular expression to find all substrings that look like
printed double values, then parse those as doubles, convert them back to
strings using your desired precision, then rebuild the argument string
based on them before actually printing it...but of course that only works
if you're looking to *decrease* precision from the default and would break
if you ever tried to print something like "version 2.3".
Post by Rich Eakin
The zones is an interesting idea. Ideally though, I think it would be nice
to use the built in print function or a custom function that took the same
parameter (Object), and control how the formatting is done. The problem
with using my own custom print function (or a logging library for that
matter), is that as far as I can tell the double.toString()'s have already
happened so my function only sees a big concatenated string.
Post by Ian Mackenzie
If you're not using string interpolation and just calling
print(someValue), then perhaps you could use a Zone
<https://www.dartlang.org/articles/zones/#example-overriding-print> to
override the print() function within a body of code to recognize doubles
and format them to a given precision? You could even get fancy with your
overridden print() function to allow passing it lists of arguments, and it
would concatenate the string versions of each while using your default
precision for doubles, so you could call (within the zone)
print(['The value of x is ', x, ' and the value of y is ', y]);
to get a form of string interpolation (unless of course you also want to
be able to print out lists as lists!).
Post by Rich Eakin
I've been working on a simulation in dart and found the double.
toStringAsFixed() method very useful in controlling how much data gets
printout to console when I'm debugging variables. I was thinking though, it
would be nice if it was possible to set a global precision for my
application or isolate, so that I did not have to write that method in
every print statement that I make. Is there any existing discussion for
something like this, or a feature request?
cheers,
Rich
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Loading...