Answered by:
numeric format with commas, proper number of leading spaces for right alignment

Question
-
User-1767698477 posted
I would like to right align my numbers in a document that appear in a column:
$ 12.00
1,000.00
300.00
So it lines up on the right side
TryCast(form.Fields("totalbcbaseincome"), PdfLoadedTextBoxField).Text = String.Format("{0,5:###,###.00}", totwages)
Dim totovertime As Integer = Convert.ToUInt64(tblloanappsrow.borovertime) + Convert.ToUInt64(tblloanappsrow.cborovertime)
TryCast(form.Fields("totalbcovertime"), PdfLoadedTextBoxField).Text = String.Format("{0,5:###.0}", totovertime)This does not work for me. How do you tell asp.net that when the number is 12, that it gets 2 zeros after the decimal point and it is padded with leading spaces to line up with 12,601..25. Just like this and so on down the column.
12.00
12,601.25
300.25
Saturday, July 4, 2020 4:39 AM
Answers
-
User-1767698477 posted
There is no HTML Kathy. I'm repeating myself here... It's all done in the code which I furnished above into a pdf document which has embedeed form fields which I access through the Trycast code you see.
I have solved my problem by drilling down into the intellisense and figuring out how to right align the numbers. The pdf document is created by mapping out an existing pdf document with form fields like so:
Dim txttotalbcbaseincome As New PdfTextBoxField(loadedPage, "totalbcbaseincome")
txttotalbcbaseincome.MaxLength = 9
txttotalbcbaseincome.Bounds = New RectangleF(264, 229, 50, 10)
txttotalbcbaseincome.BorderWidth = 0
txttotalbcbaseincome.TextAlignment = PdfTextAlignment.Right
loadedDocument.Form.Fields.Add(txttotalbcbaseincome)Once the form is saved, I move the form into my website application and run the other page with the Trycast code to populate the form fields with data from my sql db.
As you see, I have added
txttotalbcbaseincome.TextAlignment = PdfTextAlignment.Right
to each form field. This is now right aligning everything much better for me. I could not find any documentation on this in the Syncfusion site.
Now, I just need to figure out why the .01 is not lining up and I"ll be good.
Thank you.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, July 5, 2020 4:37 AM
All replies
-
User409696431 posted
The normal approach to line up the numbers on the right would be to apply a CSS style to right align the contents in the column. (text-align: right;) Since I have no idea what the HTML is for your displayed column I can't be more specific.
Saturday, July 4, 2020 5:32 AM -
User348806598 posted
Try this-
String.Format("{0:n}", 1234);
Saturday, July 4, 2020 6:39 AM -
User-1767698477 posted
I'm doing this currently and it results in:
1,234.00
12.00
14.00
12345.00
not what I'm shooting for:
1,2345.00
12.00
14.00
12,345.00
TryCast(form.Fields("rent"), PdfLoadedTextBoxField).Text = String.Format("{0:n}", Convert.ToUInt64(tblloanappsrow.rent))
TryCast(form.Fields("presentmtgpmt"), PdfLoadedTextBoxField).Text = String.Format("{0:n}", Convert.ToUInt64(tblloanappsrow.mortgage1))
TryCast(form.Fields("present2ndmtgpmt"), PdfLoadedTextBoxField).Text = String.Format("{0:n}", Convert.ToUInt64(tblloanappsrow.mortgage2))
TryCast(form.Fields("presenthazard"), PdfLoadedTextBoxField).Text = String.Format("{0:n}", Convert.ToUInt64(tblloanappsrow.homeowners))
TryCast(form.Fields("presentretax"), PdfLoadedTextBoxField).Text = String.Format("{0:n}", Convert.ToUInt64(tblloanappsrow.propertytax))Saturday, July 4, 2020 5:19 PM -
User475983607 posted
Pretty basic HTML and CSS. The following is an example using a table. I left the border so you can see the cells.
<table width="25%" border="1"> <tr> <td width="10%">$</td> <td width="90%" align="right">1,234.00</td> </tr> <tr> <td width="10%">$</td> <td width="100%" align="right">12.00</td> </tr> <tr> <td width="10%">$</td> <td width="100%" align="right">14.00</td> </tr> <tr> <td width="10%">$</td> <td width="100%" align="right">12345.00</td> </tr> </table>
The community cannot provide assistance without your HTML design.
Saturday, July 4, 2020 10:37 PM -
User409696431 posted
That's pretty much what I said in my reply. :)
Saturday, July 4, 2020 11:51 PM -
User-1767698477 posted
I did provide code. But here's some more. Happy 4th!
Please understand that I'm populating a pdf document with this code, so there is no .aspx page. See image below. I found this solution on another forum, but it does not work very well when writing to the pdf document. As you can see, to smaller numbers do not pad the front of the number with enough spaces so that it is lined up perfectly with the other larger numbers. It looks quite bad. Do you have any suggestions on how to improve ?
TryCast(form.Fields("borempbaseincome"), PdfLoadedTextBoxField).Text = String.Format("{0,13:###,###.00}", Convert.ToDecimal(borwages)) TryCast(form.Fields("borempovertime"), PdfLoadedTextBoxField).Text = String.Format("{0,13:###,###.00}", Convert.ToDecimal(tblloanappsrow.borovertime)) TryCast(form.Fields("borempbonus"), PdfLoadedTextBoxField).Text = String.Format("{0,13:###,###.00}", Convert.ToDecimal(tblloanappsrow.borbonuses)) TryCast(form.Fields("borempcommission"), PdfLoadedTextBoxField).Text = String.Format("{0,13:###,###.00}", Convert.ToDecimal(tblloanappsrow.borcommissions)) TryCast(form.Fields("bordividendsint"), PdfLoadedTextBoxField).Text = String.Format("{0,13:###,###.00}", Convert.ToDecimal(tblloanappsrow.bordividendsinterest)) 'Compute net rental income later Dim bornetrentalinc As Integer = 0 TryCast(form.Fields("bornetrentalincome"), PdfLoadedTextBoxField).Text = String.Format("{0,13:###,###.00}", Convert.ToDecimal(bornetrentalinc)) Dim borrowerotherinc As Integer = 0 If tblloanappsrow.borotherinc1amt <> 0 Then borrowerotherinc = tblloanappsrow.borotherinc1amt End If If tblloanappsrow.borotherinc2amt <> 0 Then borrowerotherinc = borrowerotherinc + tblloanappsrow.borotherinc2amt End If If tblloanappsrow.borotherinc3amt <> 0 Then borrowerotherinc = borrowerotherinc + tblloanappsrow.borotherinc3amt End If TryCast(form.Fields("borotherincome"), PdfLoadedTextBoxField).Text = String.Format("{0,13:###,###.00}", Convert.ToDecimal(borrowerotherinc)) Dim bortotalincome As Integer = borwages + tblloanappsrow.borovertime + tblloanappsrow.borbonuses + tblloanappsrow.borcommissions + tblloanappsrow.bordividendsinterest + bornetrentalinc + borrowerotherinc 'Dim bortotalincome As Integer = borwages + Convert.ToUInt64(tblloanappsrow.borovertime) + Convert.ToInt64(tblloanappsrow.borbonuses) + Convert.ToInt64(tblloanappsrow.borcommissions) + Convert.ToInt64(tblloanappsrow.bordividendsinterest) + bornetrentalinc + borrowerotherinc TryCast(form.Fields("bortotalincome"), PdfLoadedTextBoxField).Text = String.Format("{0,13:###,###.00}", Convert.ToDecimal(bortotalincome))
Sunday, July 5, 2020 2:29 AM -
User409696431 posted
Code is not what we need. The HTML is what we need. Look at the page in a browser, use the browser's tools to see the resulting HTML elements. Apply the alignment CSS to the elements containing the numbers.
Sunday, July 5, 2020 3:19 AM -
User-1767698477 posted
There is no HTML Kathy. I'm repeating myself here... It's all done in the code which I furnished above into a pdf document which has embedeed form fields which I access through the Trycast code you see.
I have solved my problem by drilling down into the intellisense and figuring out how to right align the numbers. The pdf document is created by mapping out an existing pdf document with form fields like so:
Dim txttotalbcbaseincome As New PdfTextBoxField(loadedPage, "totalbcbaseincome")
txttotalbcbaseincome.MaxLength = 9
txttotalbcbaseincome.Bounds = New RectangleF(264, 229, 50, 10)
txttotalbcbaseincome.BorderWidth = 0
txttotalbcbaseincome.TextAlignment = PdfTextAlignment.Right
loadedDocument.Form.Fields.Add(txttotalbcbaseincome)Once the form is saved, I move the form into my website application and run the other page with the Trycast code to populate the form fields with data from my sql db.
As you see, I have added
txttotalbcbaseincome.TextAlignment = PdfTextAlignment.Right
to each form field. This is now right aligning everything much better for me. I could not find any documentation on this in the Syncfusion site.
Now, I just need to figure out why the .01 is not lining up and I"ll be good.
Thank you.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, July 5, 2020 4:37 AM -
User1693814044 posted
There is no HTML KathyI assume that you do realize you are posting to a web development forum targeting asp.net?
If there is no html, then it looks like you are posting at the incorrect forum.
Syncfusion forums are located here: https://www.syncfusion.com/forums
Sunday, July 5, 2020 8:56 PM -
User-1767698477 posted
Yes you assume correctly. Yes that's where the syncfusion forums are located.
SK
Tuesday, July 7, 2020 10:22 PM