用于 Flash 的 AS3 flash 货币格式化程序
我需要帮助来扩展正确的字符串?将我的数字步进器和/或文本显示字段格式化为货币格式。您可以从此处的 CS5 flash FLA 下载 FLA。谢谢
/* start application */
import flash.geom.Matrix;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.net.URLLoader;
import flash.globalization.CurrencyFormatter;
//comboBox, I populate values displayed to users
this.comptype.addItem ( { label: "clerical" } );
this.comptype.addItem ( { label: "concrete" } );
this.comptype.addItem ( { label: "demolition" } );
this.comptype.addItem ( { label: "electricians" } );
this.comptype.addItem ( { label: "excavation" } );
this.comptype.addItem ( { label: "HVAC/Plumbing" } );
this.comptype.addItem ( { label: "oil and gas" } );
this.comptype.addItem ( { label: "road/bridge construction" } );
this.comptype.addItem ( { label: "roofing" } );
this.comptype.addItem ( { label: "sewer construction" } );
this.comptype.addItem ( { label: "truck driving" } );
this.comptype.addItem ( { label: "warehousing" } );
this.comptype.addEventListener (Event.CHANGE, selectOrder);
function selectOrder (event:Event) : void
{
if (this.comptype.selectedItem.label == "clerical") this.orderTotal.text = ("3.00");
if (this.comptype.selectedItem.label == "concrete") this.orderTotal.text = ("8.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "demolition") this.orderTotal.text = ("10.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "electricians") this.orderTotal.text = ("5.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "excavation") this.orderTotal.text = ("8.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "HVAC/Plumbing") this.orderTotal.text = ("6.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "oil and gas") this.orderTotal.text = ("13.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "road/bridge construction") this.orderTotal.text = ("10.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "roofing") this.orderTotal.text = ("18.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "sewer construction") this.orderTotal.text = ("9.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "truck driving") this.orderTotal.text = ("13.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "warehousing") this.orderTotal.text = ("7.00"); //make sure my values match the above values EXACTLY
}
this.outline.calcBtn.addEventListener (MouseEvent.CLICK, goCalc);
function goCalc (Event:MouseEvent) : void
{
this.outline.annualSavings.text = (this.staffrate.value-(14.15 + parseInt(this.orderTotal.text)))*this.payroll.value;
//this.outline.docCostMonth.text = (this.timesPerDay.value * 260) / 12 * this.docProcCost.value;
//this.outline.docCostYear.text = (this.outline.docCostMonth.text *12);
//this.outline.annualSavings.text = ((this.procAutoSaving.value * this.outline.docCostYear.text) / 100);
}
var cf:CurrencyFormatter = new CurrencyFormatter( "en_US" );
this.payroll.value = this.payrollOut;
cf.format( this.payrollOut.text ); //??
I need help in extending the proper string?? to format my numericstepper and/or text display fields to currency formatted. You can download the FLA from CS5 flash FLA HERE. Thanks
/* start application */
import flash.geom.Matrix;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.net.URLLoader;
import flash.globalization.CurrencyFormatter;
//comboBox, I populate values displayed to users
this.comptype.addItem ( { label: "clerical" } );
this.comptype.addItem ( { label: "concrete" } );
this.comptype.addItem ( { label: "demolition" } );
this.comptype.addItem ( { label: "electricians" } );
this.comptype.addItem ( { label: "excavation" } );
this.comptype.addItem ( { label: "HVAC/Plumbing" } );
this.comptype.addItem ( { label: "oil and gas" } );
this.comptype.addItem ( { label: "road/bridge construction" } );
this.comptype.addItem ( { label: "roofing" } );
this.comptype.addItem ( { label: "sewer construction" } );
this.comptype.addItem ( { label: "truck driving" } );
this.comptype.addItem ( { label: "warehousing" } );
this.comptype.addEventListener (Event.CHANGE, selectOrder);
function selectOrder (event:Event) : void
{
if (this.comptype.selectedItem.label == "clerical") this.orderTotal.text = ("3.00");
if (this.comptype.selectedItem.label == "concrete") this.orderTotal.text = ("8.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "demolition") this.orderTotal.text = ("10.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "electricians") this.orderTotal.text = ("5.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "excavation") this.orderTotal.text = ("8.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "HVAC/Plumbing") this.orderTotal.text = ("6.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "oil and gas") this.orderTotal.text = ("13.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "road/bridge construction") this.orderTotal.text = ("10.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "roofing") this.orderTotal.text = ("18.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "sewer construction") this.orderTotal.text = ("9.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "truck driving") this.orderTotal.text = ("13.00"); //make sure my values match the above values EXACTLY
if (this.comptype.selectedItem.label == "warehousing") this.orderTotal.text = ("7.00"); //make sure my values match the above values EXACTLY
}
this.outline.calcBtn.addEventListener (MouseEvent.CLICK, goCalc);
function goCalc (Event:MouseEvent) : void
{
this.outline.annualSavings.text = (this.staffrate.value-(14.15 + parseInt(this.orderTotal.text)))*this.payroll.value;
//this.outline.docCostMonth.text = (this.timesPerDay.value * 260) / 12 * this.docProcCost.value;
//this.outline.docCostYear.text = (this.outline.docCostMonth.text *12);
//this.outline.annualSavings.text = ((this.procAutoSaving.value * this.outline.docCostYear.text) / 100);
}
var cf:CurrencyFormatter = new CurrencyFormatter( "en_US" );
this.payroll.value = this.payrollOut;
cf.format( this.payrollOut.text ); //??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嘿,我希望这会有所帮助,
该函数非常简单,我们调用函数
formatCost()
如果您只想将其格式化为 0 位小数,
formatCost(value as string,0)< /代码>
如果您需要货币,请将其添加为第三个参数。
如果您需要符号出现在数字后面,请将位置设置为 1
所以...
如果需要,您可以在公式中添加更多内容,以便第 5 个变量可以是间隔符,这样您就可以将其从“,”更改为“。” (法语)或作为空格“”
Hey there I hope this helps,
The function is pretty simple, we call the function
formatCost()
If you just wish to format it to 0 decimals,
formatCost(value as string,0)
If you need a currency add that in as the 3rd parameter.
If you need the symbol to appear behind the number, have the position set to 1
So...
if wanted, you can tack on more to the formula so that the 5th variable could be the spacer, so that you could change it from a "," to a "." (for french) or as a space " "
货币格式化的更好替代方法是使用 Adobe 类 flash.globalization.CurrencyFormatter
该类非常灵活,允许您自定义区域设置的货币外观。
A better alternative for currency formatting is to use the Adobe class flash.globalization.CurrencyFormatter
This class is very flexible, allowing to you customize the currency appearance for locale.
问题是您没有注意变量类型。
this.payrollOut - 是一个文本字段
this.payrollOut.text - 是该文本字段中包含的文本
this.payroll.value 不能分配文本字段或文本值
因此您必须转换为它期望的类型 - 在本例是一个数字。
cf.format 也需要一个数字值,并将返回一个字符串。
一个使用示例可能是:
我看到的代码还有其他问题 - payrollOut 没有价值 - 因此它仍然无法按预期运行,但这解决了眼前的问题。
The issue is that you are not paying attention to the variable types.
this.payrollOut -- is a textfield
this.payrollOut.text -- is the text contained in that textfield
this.payroll.value cannot be assigned a textfield or a text value
So you must convert to the type that it is expecting -- in this case a Number.
cf.format is expecting a Number value as well, and will return a String.
an example of usage might be :
There are other issues with the code that I see -- payrollOut has no value - so it's still not going to function as expected, but this solves the immediate problem.