473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

limiting decimal places

Im doing some work for uni and I am a beginner at javascript. This is the code that I have:
var canvas;
canvas = openGraphics();

var radius;
radius = 20;

var area;
area = (radius*radius)*Math.PI;

canvas.fillEllipse( 10, 10, 250, 140 );
// drawEllipse, requires four values:
// drawEllipse( x, y, width, height );
// x and y are the coordinates of the top left corner
// width and height are what they say!

canvas.drawString( "Radius of circle:", 10, 250 );
canvas.drawString( radius, 120, 250 );
canvas.drawString( "area of circle", 10, 280 );
canvas.drawString( area, 120, 280 );

canvas.paint();

Can someone please tell me how to limit the amount of decimal places please.
Feb 19 '07 #1
2 2440
r035198x
13,262 8TB
Im doing some work for uni and I am a beginner at javascript. This is the code that I have:
var canvas;
canvas = openGraphics();

var radius;
radius = 20;

var area;
area = (radius*radius)*Math.PI;

canvas.fillEllipse( 10, 10, 250, 140 );
// drawEllipse, requires four values:
// drawEllipse( x, y, width, height );
// x and y are the coordinates of the top left corner
// width and height are what they say!

canvas.drawString( "Radius of circle:", 10, 250 );
canvas.drawString( radius, 120, 250 );
canvas.drawString( "area of circle", 10, 280 );
canvas.drawString( area, 120, 280 );

canvas.paint();

Can someone please tell me how to limit the amount of decimal places please.
Javascript != Java so I'll move this to the Javascript forum
Feb 19 '07 #2
acoder
16,027 Expert Mod 8TB
Can someone please tell me how to limit the amount of decimal places please.
Use toFixed(decimalPlaces). See this page. He also has a custom Javascript object called NumberFormat which can do a lot more.

btw, welcome to The Scripts, you spelt your username/handle wrong(!)
Feb 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
3
by: Brent Bortnick | last post by:
Does anyone know how to find out the number of decimal places a number has. I need this info so that i can round to 3 decimal places if the number has 3 decimal places or to 2 decimal places if...
2
by: Carl G | last post by:
I am storing a 0.000 a System.Decimal in a DataRow. On retrieval the value is only 0 without the three decimal places. It looks like the Get property returns System.Decimal.Zero, but why???? I...
10
by: Rogue Chameleon | last post by:
Hi all I have a input filed of type "textbox" into which I am expecting to get currency values (ie. 199.99). Is there a way that I can restrict the user to only entering 2 values after the...
4
by: italia | last post by:
I changed the Fieldsize Property from text to Long Integer and Decimal Places = 6. I had decimals in the original field. But after the transfer, the digits after the decimals are gone. Now...
8
by: nick | last post by:
printf("%lf",3.25); the result is 3.25000 i want the answer correct to 3 decimal places What should i do? thanks!
3
by: mohaaron | last post by:
Hello All, Does anyone know of a way to test a decimal for the number of places it has before and after the decimal? I need to do something like this. decimal value1 = 172.45; // If value1...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
3
by: David | last post by:
Any ideas why this statement: mBalanceChange = Double.Parse(strCurrentBalance, Globalization.NumberStyles.AllowThousands Or Globalization.NumberStyles.AllowDecimalPoint) - mBalanceDouble ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.