Home php教程 PHP开发 In Flex, format the value of a certain column of the table numerically and add % to find the percentage.

In Flex, format the value of a certain column of the table numerically and add % to find the percentage.

Dec 27, 2016 pm 04:28 PM

1. Problem background

Generally, you need to format the value of a column in the table, multiply the value by 100, keep two decimal places, and add "%"

2. Implementation example

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx"

width="100%" height="100%" fontSize="12"

fontFamily="微软雅黑">

<s:layout>

<s:BasicLayout/>

</s:layout>

<fx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

import mx.events.FlexEvent;

  

[Bindable]

//表格数据绑定

private var gridArray:ArrayCollection = new ArrayCollection([

{week:"星期一",apple:"3676",rate:"0.7868"},

{week:"星期二",apple:"4534",rate:"0.65454"},

{week:"星期三",apple:"6758",rate:"0.876454"},

{week:"星期四",apple:"9808",rate:"0.34224"},

{week:"星期五",apple:"6567",rate:"0.9876523"},

{week:"星期六",apple:"9000",rate:"0.566777"},

{week:"星期日",apple:"4533",rate:"0.988787"}

]);

  

/**

* 对表格中的比率进行格式化

*/

private function formatDataGrid(item:Object,column:DataGridColumn):String

{

var tempData:Number = item.rate*100;

var data:String = dataFormatter.format(tempData);

return data+"%";

}

  

]]>

</fx:Script>

<fx:Declarations>

<!--格式化数字-->

<mx:NumberFormatter id="dataFormatter" precision="2" rounding="up"/>

</fx:Declarations>

  

<mx:VBox width="100%" height="100%" paddingBottom="10" paddingLeft="10" paddingRight="20"

paddingTop="10" horizontalAlign="center">

<mx:DataGrid id="dataGrid" width="100%" height="90%" dataProvider="{gridArray}" textAlign="center">

<mx:columns>

<mx:DataGridColumn headerText="星期" dataField="week"/>

<mx:DataGridColumn headerText="苹果" dataField="apple"/>

<mx:DataGridColumn headerText="比率" dataField="rate" labelFunction="formatDataGrid"/>

</mx:columns>

</mx:DataGrid>

  

</mx:VBox>

</s:Application>

Copy after login

(1) Multiply the decimal by 100

var tempData:Number = item.rate*100;

(2) Format the value , keep two decimal places

var data:String = dataFormatter.format(tempData);

(3) Add percent sign

return data+"%";

3. Implementation results

In Flex, format the value of a certain column of the table numerically and add % to find the percentage.

For more Flex, digitally format the value of a column in the table and find the percentage to add %. For related articles, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)