This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Multiply does not work

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have html and jave script,
I am doing the following in it.
1. om second column, first line I put in a number
2. Second column give number auto
3 press multiply button to get answer

on second line column 4, I add number, and just press multiply.

The first two is working, but the last two does not work, I have tried to find the problem, but can not see it.

I will change the font info to css, when I get it to work

 
Marshal
Posts: 76120
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I shall move you to our HTML forum. Your multiplication does appear to be working, but you are displaying the product in the sum box.
 
Campbell Ritchie
Marshal
Posts: 76120
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why have you got the = assignment operator twice in the same line?
 
Hendrik Bezuidenhout
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Why have you got the = assignment operator twice in the same line?



The second = is for the value to be used for part of miltiply

 
Saloon Keeper
Posts: 14099
319
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

The toLocaleString() function takes an optional 'options' parameter which has a 'maximumFractionDigits' property that defaults to 3.

The operands to your 'test2BTC' multiplication are too small, the answer is rounded to "0.000" which is displayed as "0".

The same problem occurs with your first two multiplications: Notice that the results never have more than 3 fractional digits.

To solve your issue, specify the maximum number of fractional digits you want to display, in the range 0 to 20:
 
Stephan van Hulst
Saloon Keeper
Posts: 14099
319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hendrik Bezuidenhout wrote:

Campbell Ritchie wrote:Why have you got the = assignment operator twice in the same line?



The second = is for the value to be used for part of miltiply


Campbell was really asking a rhetorical question. He means that using multiple assignments in a single statement is poor programming. Instead, split the expression in two separate statements.
 
Hendrik Bezuidenhout
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Welcome to CodeRanch!

The toLocaleString() function takes an optional 'options' parameter which has a 'maximumFractionDigits' property that defaults to 3.

The operands to your 'test2BTC' multiplication are too small, the answer is rounded to "0.000" which is displayed as "0".

The same problem occurs with your first two multiplications: Notice that the results never have more than 3 fractional digits.

To solve your issue, specify the maximum number of fractional digits you want to display, in the range 0 to 20:



Thank you, got that working

 
Hendrik Bezuidenhout
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:

Hendrik Bezuidenhout wrote:

Campbell Ritchie wrote:Why have you got the = assignment operator twice in the same line?



The second = is for the value to be used for part of miltiply


Campbell was really asking a rhetorical question. He means that using multiple assignments in a single statement is poor programming. Instead, split the expression in two separate statements.



I am new to JavaScript, still figuring it out, so there will be bad programing lines,
 
Campbell Ritchie
Marshal
Posts: 76120
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The double = is still difficult to read and understand.
 
Hendrik Bezuidenhout
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:The double = is still difficult to read and understand.



I see , got this from one person that showed me, so i am not sure how to do it in two lines
 
Campbell Ritchie
Marshal
Posts: 76120
362
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know much JS, but try the following two versions. I think the first version is better because there is no repetition of the number literal 0.00001017.Similarly, separate the removal of commas (line 153) from the assignment to num11.
 
Hendrik Bezuidenhout
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I don't know much JS, but try the following two versions. I think the first version is better because there is no repetition of the number literal 0.00001017.Similarly, separate the removal of commas (line 153) from the assignment to num11.



Thank you for your help on this, got it working
 
Campbell Ritchie
Marshal
Posts: 76120
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done

Please avoid quoting the whole of the preceding post.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic