double peratusE = ((double)(bilanganE / calonAmbil)) * 100.00;
Label peratusELabel = row.Cells[16].FindControl("peratusELabel") as Label;
peratusELabel.Text = String.Format("{0:0.00}", peratusELabel);
i use that particular code to calculate the percentage and to assign the percentage value to a label. however, when running it, it displays "System.Web.UI.WebControls.Label" instead of the value.
for your information: i use
double peratusD = ((double)(bilanganD / calonAmbil)) * 100.00;
Label peratusDLabel = row.Cells[14].FindControl("peratusDLabel") as Label;
peratusDLabel.Text = String.Format("{0:0.00}", peratusD);
but this time it works just fine. i'm stucked.
It should be:
peratusELabel.Text = String.Format("{0:0.00}", peratusE);
In your first code block you are formatting a Label object, not a double object.
Related
I counldn't set the width with Interop.
My code is :
double kA = ((Excel.Range)st.Columns[1]).EntireColumn.Width;
double kB = ((Excel.Range)st.Columns[2]).EntireColumn.Width;
int KNA = Convert.ToInt32(kA + kB);
//((Excel.Range)st.Columns[1]).EntireColumn.ColumnWidth = kA + kB;
Console.WriteLine(KNA);
((Excel.Range)st.Columns[1]).ColumnWidth = KNA;
Console.WriteLine(((Excel.Range)st.Columns[1]).EntireColumn.Width);
((Excel.Range)st.Columns[2]).EntireColumn.Delete();
Both kA and kB is 59.25,and KNA is 118.But the actual width of Column A is 801.75,and it couldn't be modified any way.
I use ((Excel.Range)st.Columns1).ColumnWidth = KNA;
But the columnA width couldn't be change.
What's wrong?
I tried to change the initial columnWidth of column A&B,and I got the different value of new column width but is still more larger than KNA,about 6.8 times each time.
Before run code:
After run code:
I use columnWith to get and set columnwidth,and It's OK.
my doubles get not rounded as expected. Simple example:
int b = 23;
double DurchflussAktBit = 99.5;
double bDurchfluss = 0;
bDurchfluss = DurchflussAktBit * Convert.ToDouble(b) / (double)60;
Math.Round(bDurchfluss, 2);
I get the value 38.141666666666666 for bDurchfluss even after the rounding, I expect the value 38.14. Also tried Math.Round((decimal)bDurchfluss, 2); but gives me the same value.
Where is the error in my code?
Math.Round returns the rounded number - it does not update the number you passed it.
You need to take the return value and assign it to your variable:
bDurchfluss = DurchflussAktBit * Convert.ToDouble(b) / (double)60;
bDurchfluss = Math.Round(bDurchfluss, 2);
How can i measure the width of whitespace in winrt.
I'm trying the below code for calculate the size,
For example,
var text = " ";
TextBlock txtBlock = new TextBlock();
txtBlock.Text = text;
txtBlock.FontSize = 14;
...
txtBlock.Measure(size);
var actualWidth = txtBlock.ActualWidth;
But i'm getting width as 0. Please any one help me.
Call Measure() then Arrange() and then ActualWidth and ActualHeight will be updated. This works for me.
I want to be able to set the number of lines in a multilined TextBox.
I've tried the following:
int initHeight = textBox1.Height;
textBox1.Height = initHeight * numOfLines;
But this makes it too large when numOfLines gets large. So then I tried this:
float fontHeight = textBox1.CreateGraphics().MeasureString("W", textBox1.Font).Height;
textBox1.Height = fontHeight * numOfLines;
But this was too small when numOfLines was small, and too large when numOfLines was large.
So I'm doing SOMETHING wrong... any ideas?
This would set the exact Width & Height of your multi line Textbox:
Size size = TextRenderer.MeasureText(textBox1.Text, textBox1.Font);
textBox1.Width = size.Width;
textBox1.Height = size.Height + Convert.ToInt32(textBox1.Font.Size);
Something like this should work:
Size size = TextRenderer.MeasureText(textBox1.Text, textBox1.Font);
textBox1.Width = size.Width;
textBox1.Height = size.Height;
This was from C# Resize textbox to fit content
What you are doing should work, but you need to set the MinimumSize and MaximumSize I am not 100% positive, but I think this constraint will still hold if height is set via code
From the documentation of Graphics.MeasureString:
To obtain metrics suitable for adjacent strings in layout (for example, when implementing formatted text), use the MeasureCharacterRanges method or one of the MeasureString methods that takes a StringFormat, and pass GenericTypographic. Also, ensure the TextRenderingHint for the Graphics is AntiAlias.
As such, you should use one of these overloads, such as this one, which allow you to specify StringFormat.GenericTypograpic to get the required size.
Try this:
float fontHeight;
using (var g = textBox1.CreateGraphics())
fontHeight = g.MeasureString("W", textBox1.Font, new PointF(), StringFormat.GenericTypograpic).Height;
I want to type conversion of following.
My C# code is.
float percentage = (present/total) * 100;
lblPercentage.Text += String.Format("{0:0.00}", (float)present / (float)total);
It gives output like: 0.71 but I want output something like: 71
I think you should use {0:p} as the format then itt would display properly with the % sign