4 Replies - 586 Views - Last Post: 11 July 2016 - 07:25 AM

#1 tonyal  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 23-September 14

Scientific notation question

Posted 09 July 2016 - 06:58 PM

Hi, I'm new to PERL and I'm trying to figure out how to print out a scientific notation as 1.255000e+2

I put down:

printf "The number in scientific notation is %.6e  \n", 1.255000;



the printout is 1.255000e+00. Any help would be greatly appreciated!
Thanks in advance.
Is This A Good Question/Topic? 0
  • +

Replies To: Scientific notation question

#2 andrewsw  Icon User is offline

  • say what now
  • member icon

Reputation: 6410
  • View blog
  • Posts: 25,909
  • Joined: 12-December 12

Re: Scientific notation question

Posted 09 July 2016 - 11:37 PM

1.255000e+00 this is correct. If you want 1.255000e+2 then this represents the value 125.5.
Was This Post Helpful? 2
  • +
  • -

#3 tonyal  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 23-September 14

Re: Scientific notation question

Posted 10 July 2016 - 05:40 PM

View Postandrewsw, on 09 July 2016 - 11:37 PM, said:

1.255000e+00 this is correct. If you want 1.255000e+2 then this represents the value 125.5.


Thanks, but it's supposed to print out "1.255000e+2" for the assignment it's we have to make our text print out the same as the question in the book. Thank you though! :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2517
  • View blog
  • Posts: 4,001
  • Joined: 21-June 11

Re: Scientific notation question

Posted 10 July 2016 - 06:01 PM

If you want it to print out as that, you'll need to multiply it by 100 (or just write 125.5 as Andrew suggested). By itself 1.255 is not equal to 1.255e+2, so there's no reason why print would ever print it out as such. That's like writing print 42 and expecting that to come out as 23.
Was This Post Helpful? 1
  • +
  • -

#5 tonyal  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 23-September 14

Re: Scientific notation question

Posted 11 July 2016 - 07:25 AM

View Postsepp2k, on 10 July 2016 - 06:01 PM, said:

If you want it to print out as that, you'll need to multiply it by 100 (or just write 125.5 as Andrew suggested). By itself 1.255 is not equal to 1.255e+2, so there's no reason why print would ever print it out as such. That's like writing print 42 and expecting that to come out as 23.

Ah, okay thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1