Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 10, 2014 Sum a lot of numbers... | ||||
---|---|---|---|---|
| ||||
Hi :) I need to sum a list of numbers... but, when I calculate the sum of this numbers, I got a simplify representation of sum: 2.97506e+,12 How I can make to get the correctly representation of this number ? |
July 10, 2014 Re: Sum a lot of numbers... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandre | PS: that is my code:
import std.stdio, std.algorithm, std.range, std.conv;
string InsertComma(string val)
{
return val[0 .. $-2] ~ "," ~ val[$-2 .. $];
}
int main(string[] argv)
{
auto x = "oi.txt"
.File
.byLine
.filter!(line => line[0] == '1')
.map!(line => line[127 .. 140].to!real)
.sum;
auto valor = to!string(x);
write(InsertComma(valor));
readln();
return 0;
}
On Thursday, 10 July 2014 at 17:16:01 UTC, Alexandre wrote:
> Hi :)
>
> I need to sum a list of numbers... but, when I calculate the sum of this numbers, I got a simplify representation of sum:
>
> 2.97506e+,12
>
> How I can make to get the correctly representation of this number ?
|
July 10, 2014 Re: Sum a lot of numbers... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandre | On Thu, 10 Jul 2014 17:16:00 +0000, Alexandre wrote:
> Hi :)
>
> I need to sum a list of numbers... but, when I calculate the sum of this numbers, I got a simplify representation of sum:
>
> 2.97506e+,12
>
> How I can make to get the correctly representation of this number ?
A full decimal representation can be gotten with `format("%f", n);`
|
July 10, 2014 Re: Sum a lot of numbers... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Justin Whear | On Thu, 10 Jul 2014 17:17:40 +0000, Justin Whear wrote:
> On Thu, 10 Jul 2014 17:16:00 +0000, Alexandre wrote:
>
>> Hi :)
>>
>> I need to sum a list of numbers... but, when I calculate the sum of this numbers, I got a simplify representation of sum:
>>
>> 2.97506e+,12
>>
>> How I can make to get the correctly representation of this number ?
>
> A full decimal representation can be gotten with `format("%f", n);`
And if you need more than the default 6 digits of precision after the decimal, you can use a precision specifier, e.g. for 10 digits: `format ("%.10f", n)`
|
Copyright © 1999-2021 by the D Language Foundation